Thursday 25 June 2015

A little bit more on git reset and checkout

HEAD Index Workdir WD Safe?
Commit Level
reset --soft [commit] REF NO NO YES
reset [commit] REF YES NO YES
reset --hard [commit] REF YES YES NO
checkout [commit] HEAD YES YES YES
File Level
reset (commit) [file] NO YES NO YES
checkout (commit) [file] NO YES YES NO
*WD Safe means that this action will not affect files in the workdir

The order of underlying actions on HEAD, index and workdir is the following:
The reset command overwrites these three trees in a specific order,
stopping when you tell it to:
  Move the branch HEAD points to (stop here if --soft)
  Make the Index look like HEAD (stop here unless --hard)
  Make the Working Directory look like the Index

git reset file - is actually a shortcut for git reset --mixed HEAD file and does essentially unstage

Discrard all local commits on master:
git fetch --all
git log origin/master
to find the latest commit on the remote, and
git reset --hard c0mm1tID
to reset down to this commit


Source:

This presentation might also be helpful to quicly review some interesting git features: