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
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.