Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between git reset --hard HEAD and git checkout .?

Tags:

If I make changes to the working tree and have not yet committed, and I would like to revert the changes I have made, is there a difference between

git reset --hard HEAD

and

git checkout .

?

like image 515
bsamek Avatar asked Feb 26 '11 18:02

bsamek


People also ask

What is the difference between git reset and git checkout?

Unlike git reset , git checkout doesn't move any branches around. This is useful for quickly inspecting an old version of your project. However, since there is no branch reference to the current HEAD , this puts you in a detached HEAD state.

What is the difference between head and checkout in git?

@phd checkout with HEAD and without it are not doing exactly the same thing. For example git checkout -- . will not bring back a deleted file that has already been staged, but git checkout HEAD -- . will bring such a file back. @FlyingFoX Ok, without explicit HEAD git checks files out from the index.

What is the difference between reset and reset git?

git reset --soft , which will keep your files, and stage all changes back automatically. git reset --hard , which will completely destroy any changes and remove them from the local directory. Only use this if you know what you're doing.

What does git reset -- hard head do?

Running git reset --hard ORIG_HEAD will let you go back to where you were, but it will discard your local changes, which you do not want. git reset --merge keeps your local changes.


1 Answers

git checkout -- . will obviously only work on the current directory (and subdirectories thereof), git reset --hard will operate on the complete working tree.

git checkout -- . will only update the working tree and leave already staged files as is, whereas git reset --hard will match index and working tree with the HEAD commit.

when used with a refspec:

  1. reset will set the current branch head to the given commit (and matches index and working tree)
  2. checkout will switch to that branch, leaving local changes intact, when they touch files which did not change between the current branch and the branch to be checked out
like image 147
knittl Avatar answered Nov 09 '22 21:11

knittl