Mastering git, Part 3 (Undo local changes, git revert, git reset, git amend and git clean)
1. Checkout The git checkout moves the HEAD ref pointer to a specified commit. To demonstrate this, consider the following example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
mkdir remote_repose mkdir repos && cd repos git init git init --bare ../remote_repose/ git remote add origin ../remote_repose/ touch A.txt git add -A git commit -a -m 'A Added' git push --set-upstream origin master touch B.txt git add -A git commit -a -m 'B Added' git push touch C.txt git add -A git commit -a -m 'C Added' git push touch D.txt git add -A git commit -a -m 'D Added' git push |
Now you can change the HEAD with:
1 |
git checkout <commit-id> |
or
1 |
git checkout HEAD~<number> |
you can find all commits again by:
1 |
git log --all |
For instance:
1 |
git checkout HEAD~2 |
1 |
gitk --all |
1.2 Detached HEAD Any checkout of a commit that is not […]