Cjku/git: Difference between revisions

650 bytes added ,  29 October 2014
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 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).
# <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 abort, since it's really annoyed for a new hand.
I separate an individual section to discuss git-checkout aborting, since it's somehow annoyed to git new hands.


If git think you may lose local change in working directory, it aborts your checkout command. Here is an example
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


Go back to [[reset and checkout]] section, ..............TBD
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  
Confirmed users
1,643

edits