GIT MISCThu, Oct 2, 2014
working tree, working directory
index, staging area, cache, staged snapshot
commit[ted] history, commit[ted] snapshot
between the committed history & staging area
commitsubmit changes from staging area to committed history
resetrevert changes from committed history back to staging area
between the staging area & working tree.
addsubmit changes from working tree to staging area, preparing for committing.
rmremove file(s) from stageing area, so they become untracked.
checkoutrestore changes from staging area or a specific commit of committed history to working directory.
unstages changes in staging area. v git reset
or, if you ask for more, uncommits changes in history.
git reset <commit-ish>
untracks file(s) previously tracked in staging area.
git rm --cache <paths>
or, if you ask for more, removes file(s) in the work directory.
git rm <paths>
git reset <commit-ish> <paths>only update staging area.
git checkout <paths>fetch
<paths>from staging area to working direcotry.
git checkout <commit-ish>fetch
<paths>from history to both index & working direcotry.
git Rebase Sub-command
no additional merge commit
linear commit history
tracability: the evidences of merging are wiped away.
Golden rule of
never use it on public branches.
When to use
Incorporating upstream changes into a feature branch
Integrating a approved feature
The parameters that you pass to
git checkoutdetermine their scope. When you don’t include a <file path> as a parameter, they operate on whole commits. Note that git revert has no file-level counterpart
Commit level operations
git reset --[soft | mixed | hard] <commit-ish> move branch tips backwards
or even forwards, while affecting staging area & working direcotry according to
options it is given.
|option||history||staging area||working directory|
git checkout <commit-ish> dose not move tips around.
git revert undo commits by adding a new commit. it is a safe (reversible) way
to undo commits, while
git reset is dangerous (irreversible) way to undo
File level operations
git [reset|checkout] <commit-ish> <pathspec>
|command||history||staging area||working directory|
|command||commit level||file level|
||discard commits in private branches or throw away uncommited changes||unstage a file|
||swtich between branches or inspect old snapshots||discard changes in the working directory|
||undo commits in public branches||N/A|