Confirmed users
1,643
edits
| Line 377: | Line 377: | ||
# <span style="color:red">(Different with git-reset)</span> Change the referee(branch) of HEAD. | # <span style="color:red">(Different with git-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">(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 git-reset-hard)</span> Regenerate index according to the tree of the new | # <span style="color:red">(Similar to git-reset-hard)</span> Regenerate index according to the tree of the new assigned commit; 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: A file in working directory will be overwritten only if it's a tracked one and the content of that file in tree is different between two branches. 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 | ||
===checkout abort=== | ===checkout abort=== | ||
I separate an individual section to discuss checkout | I separate an individual section to discuss git-checkout aborting, since it's somehow annoyed to git new hands. | ||
Briefly speaking, if git think you may lose local change in working directory, it aborts your git-checkout command. Here is an example | |||
<span style="color:blue">$ mkdir checkout_abort && cd checkout_abort</span> | <span style="color:blue">$ mkdir checkout_abort && cd checkout_abort</span> | ||
<span style="color:blue">$ git init</span> | <span style="color:blue">$ git init</span> | ||
| Line 408: | Line 408: | ||
Aborting | Aborting | ||
In previous section, I mentioned | |||
''git-checkout regenerate index according to the tree of the new assigned commit; 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: A file in working directory will be overwritten only if it's a tracked one and the content of that file in tree is different between two branches. Unchanged files and untracked files are out of scope. checkout-aborting has direct relation with this principle).'' | |||
The definition of dirty files | |||
Then, how to fix aborting? Depend on your situation, there are several strategies | Then, how to fix aborting? Depend on your situation, there are several strategies | ||