Confirmed users
1,643
edits
| Line 292: | Line 292: | ||
===change history=== | ===change history=== | ||
== | ==Reset and checkout== | ||
git-checkout and git-reset are a bit confusing at times, at least for me. The functionalities of these two commands are overlapped: | git-checkout and git-reset are a bit confusing at times, at least for me. The functionalities of these two commands are overlapped: | ||
# Both of them are able to move HEAD. | # Both of them are able to move HEAD. | ||
| Line 374: | Line 374: | ||
or: git checkout [options] [<branch>] -- <file>... | or: git checkout [options] [<branch>] -- <file>... | ||
No | No wonder, there are also two forms in git-checkout: checkout HEAD to a '''branch''' or checkout '''files''' from a '''branch'''. Let's talk about the first form: checkout HEAD to a '''branch''' or checkout | ||
checkout a branch | # <span style="color:red">(Different with git-reset)</span> Change the referee(branch) of HEAD. | ||
# <span style="color:red">(Different with reset)</span> Change the referee(branch) of HEAD. | # <span style="color:red">(Different with git-reset)</span> There is no hardness-choice in git-checkout. git-checkout always modifies working directory and the index. | ||
# <span style="color:red">(Similar to reset | # <span style="color:red">(Similar to git-reset-hard)</span> Regenerate index according to the tree of the new assign commit object; Overwrite all '''modified''' tracked files in working directory. The only difference between git-reset-hard and git-checkout is git-reset-hard never aborting, while git-checkout will.(Note: only tracked and dirty files will be overwritten by git-checkout. Unchanged files and untracked files are out of scope. checkout-aborting has direct relation with this principle). | ||
Scott Chacon/Ben Straub wrote a fantastic article with regards to reset, and deserves you spend time on: http://git-scm.com/blog/2011/07/11/reset.html | Scott Chacon/Ben Straub wrote a fantastic article with regards to reset, and deserves you spend time on: http://git-scm.com/blog/2011/07/11/reset.html | ||