Saturday, October 13, 2012

Git cheatsheet


My random notes on Git use.

   
   
   
g checkout path for path, reset WT to Index (change WT)
g checkout tree-ish path for path, reset WT and Index to tree-ish (change WT and Index)
g checkout branch switches branch by updating the index, working tree, and HEAD to reflect the specified branch (current branch is switched)
g checkout commit_id check out a commit for inspection and discardable experiments.
(current branch is switched)
g checkout -p commit_id don't switch branch; update working tree and Index interactively.
E.g. g checkout -p HEAD
g checkout -b branchname\
    start_point
create a new branch from start_point and switch to it.
(current branch is switched)
g checkout not sure yet!
   
g reset path for path, reset index to HEAD (WT and branch are not touched)
g reset commit path for path, reset index to commit (WT and branch are not touched)
g reset --option commit reset HEAD to commit, and reset index or WT according to option
(http://www.kernel.org/pub/software/scm/git/docs/git-reset.html)
--soft only reset HEAD
--mixed (default) reset HEAD and index
--hard reset HEAD, index, and WT
--merge reset HEAD and index;
for each file:
    HEAD != commit, then reset WT;
    Index != WT, then don't reset WT;
    HEAD != commit && Index != WT, then abort.
--keep reset HEAD and index;
for each file:
    HEAD == commit, then don't reset WT;
    HEAD != commit && WT == Index && Index == HEAD, then reset WT;
    HEAD != commit && has local changes, then abort.
   
git rebase -i upstream interactively rebase. You can choose to squash commits.
E.g. git rebase -i HEAD^4, git rebasei HEAD@{4}