8

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?

1615903
  • 32,635
  • 12
  • 70
  • 99
CrazySynthax
  • 13,662
  • 34
  • 99
  • 183
  • 2
    https://stackoverflow.com/questions/3639342/whats-the-difference-between-git-reset-and-git-checkout – K. Kirsz Jul 03 '17 at 09:02
  • Possible duplicate of [What's the difference between "git reset" and "git checkout"?](https://stackoverflow.com/questions/3639342/whats-the-difference-between-git-reset-and-git-checkout) – Kai Jul 03 '17 at 09:09

3 Answers3

3

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

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 <commit_id>, 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.
hspandher
  • 15,934
  • 2
  • 32
  • 45
  • The OP asked about reset hard and checkout dot, not about resetting or checking out a commit hash. (not my downvote) – Tim Biegeleisen Jul 03 '17 at 09:08
  • @TimBiegeleisen I have answered that part in my first line, that there's isn't much difference. Difference only arise when we use commits with these commands. – hspandher Jul 03 '17 at 09:25
0

git checkout get update data from Git server, also keep your change at local machine.

git reset --hard make a copy identity like Git server at a specific HEAD, and discard all change at your local machine.

Vy Do
  • 46,709
  • 59
  • 215
  • 313