1. b.93z.org
  2. Notes

Important things not mentioned in “Git in 5 minutes” tutorials

How to view staged diff

How to view diff for things to be committed (after git add invocation), that is, “staged”:

$ git diff --cached

How to look at file’s contents at some stage

How to look at specific file’s contents at some stage (HEAD~4 is “some stage”):

$ git show HEAD~4:somedir/somefile

How to change specific commit

How to change specific commit (feed5e):

$ git rebase feed5e^ --interactive

This command will fire up editor: modify, replace pick with edit for that commit, save, and close editor. Then do necessary changes (for instance, git add somefile) and do usual git commit --amend. To finish, use git rebase --continue. So:

  1. Start rebase:

    $ git rebase feed5e^ --interactive
    
  2. Set ”edit” for commits you want to change.

  3. Do changes to files.

  4. Commit changes:

    $ git commit --amend
    
  5. Continue the rebase:

    $ git rebase --continue
    

© 2008–2017 93z.org