Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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 difference between them?

like image 509
CrazySynthax Avatar asked Jul 03 '17 08:07

CrazySynthax


1 Answers

Here is the difference between the two commands:

git checkout .

This tells Git to checkout the current folder, whatever that is, from the current branch and replace the working folder with it. But this does not affect other areas of the working folder, nor does it involve the stage.

git reset --hard

This resets the entire working directory and stage to the HEAD of the current branch. You can think of this as effectively nuking everything which has happened since your last commit.

Generally speaking hard reset is something you won't use that often, whereas checking out files/folders from various places is more common.

like image 176
Tim Biegeleisen Avatar answered Sep 22 '22 23:09

Tim Biegeleisen