Git Back to the Future

(a.k.a. Rewriting History in Git)

  • git reset
  • git commit --amend
  • git rebase
  • git rebase -i
  • git reflog

prepare branch

HEAD

HEAD

git reset

git reset --hard HEAD^

HEAD

HEAD

git reset --soft

HEAD

HEAD

git reset --hard HEAD~N

HEAD

HEAD~4

HEAD

git commit --amend

HEAD

git rebase <BRANCH>

HEAD

HEAD

git rebase
[-i | --interactive]

🤩

🇨🇭🔪

git rebase -i HEAD~N

Manipulate commits by:

 

  • Re-ordering

 

  • Squashing

 

  • Editing/Splitting

 

  • Deleting

🏆Golden rule:

 

Don't push -f alt timelines to Public branches

handy tip: git pull --rebase

 

git pull --rebase origin master

 

(instead of merge commit master)

git reflog

(a.k.a. how to save your ass)

Thx!