What is the difference between “git reset --hard” and “git checkout .”?

后端 未结 3 1528
心在旅途
心在旅途 2021-01-19 02:47

When I want some changes in my project and I want to return to the state of the last commit, I can use these both options. Do they actually do the same thing or is there any

3条回答
  •  北海茫月
    2021-01-19 03:38

    There are same if you don't follow them with any commit id i.e. they resets your state to the latest commit. However if you do reset --hard , it changes the HEAD of your current branch to commit id specified, whereas checkout creates a temporary branch.

    git checkout 6a0ff74 
    # would create a temp branch with its HEAD pointed to commit id
    # you can just checkout your original branch.
    
    git reset --head 6a0ff74
    # would change the `HEAD` of the current branch. To reverse the change
    # you must find the latest commit id and `reset --hard` to it again.
    

提交回复
热议问题