Git checkout with dot

前端 未结 2 744
天涯浪人
天涯浪人 2020-12-01 05:03

What difference between next git commands:

git  checkout branch
git  checkout branch .
git  checkout  .  #<-- used at the branch
2条回答
  •  不思量自难忘°
    2020-12-01 05:42

    The above explanation is fine but let me explain with examples.

    git checkout can be used with files folders and branches.

    Let say there is index.html file and dev folder.

    If I accidentally change index.html and i want to undo that I will simply run git checkout index.html. It will get my file back to its original form.

    Now let say I made some changes inside dev folder and and want those changes back inside dev folder. If I will use git checkout dev and if there is any dev branch then it will checkout that dev branch rather than folder named dev.

    So rather I would run git checkout -- dev

    Now this bare double dash stands for current branch. So above command is asking from git is that please give me 'dev' named folder from current branch.

    Lets talk about your use case.

    git checkout branch this command will simply checkout the branch named 'branch'

    git checkout branch . The second command will tell git that please checkout . or current folder name from the branch named 'branch'

    git checkout . #<-- used at the branch as you are saying first you switched to branch named 'branch' using git checkout branch then you are simply doing git checkout . Now there is no branch named . so it will simply pull down current folder name from current branch.

提交回复
热议问题