Skip to content

Instantly share code, notes, and snippets.

@nicknovitski
Last active December 11, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicknovitski/4661654 to your computer and use it in GitHub Desktop.
Save nicknovitski/4661654 to your computer and use it in GitHub Desktop.

rebase chat 1/30

who is this asshole

noted canadian actor and musician keanu reeves

Rule #1

Always Rebase

Rule #2

ALWAYS REBASE

and we're done

Programmer Poetry

"Rebase words are uttered only by the rebase, and can for such at once be understood." -W.H. Auden

man git-rebase

git rebase [upstream]

  1. All changes made by commits in the current branch which are not in [upstream] are saved to a temporary area.
  2. The current branch is reset to [upstream].
  3. The saved changes are reapplied to the current branch.

and we're done

okay, let's have pictures instead

Before

a git object tree before rebasing

After

a git object tree after rebasing

That sounds dangerous!

richard pryor, famous rebaser

Dangerous things can be useful

alcohol

social drinking

tobacco

puerto rico card indicating point value of tobacco

firearms

a gun of a thousand uses

and anyway, we have backups

$ git push origin featurebranch
$ git reset --hard master  
$ say yawn
$ git pull origin featurebranch

what can we do with this?

Use case number one

$ git checkout master
$ git pull origin master
$ git checkout feature/12345-actual-branch-name
$ git rebase master

eat the merge-elephant one bite at a time

First, rewinding head to replay your work on top of it...
Applying: added arkleseizure to gemfile 
Applying: change sneeze specs to use arkleseizure
Applying: adding new backbone model and view
Applying: track sneezes
error: could not apply 07e9061...make javascript analytics event-driven
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' and run 'git rebase --continue'
Could not apply 07e9061...make javascript analytics event-driven

an elephant, conveniently marked for its inevitable slaughter

eliminate merge commits

They are noise. You do not need them. Stop making more.

Use cases number 2 to two million

git rebase --interactive [the last commit you don't want to change]

aka

git rebase -i

also aka

strongest subcommand there is

it looks like this

pick 52ee076 add commander to dependencies¬
pick e8c3194 add first version of bin command¬
pick 9852e66 separate card and set reporters¬
pick d2b069a have cli dynamically load version information¬

# Rebase dd601d9..d2b069a onto dd601d9¬
#¬
# Commands:¬
#  p, pick = use commit¬
#  r, reword = use commit, but edit the commit message¬
#  e, edit = use commit, but stop for amending¬
#  s, squash = use commit, but meld into previous commit¬
#  f, fixup = like "squash", but discard this commit's log message¬
#  x, exec = run command (the rest of the line) using shell¬
#¬
# If you remove a line here THAT COMMIT WILL BE LOST.¬
# However, if you remove everything, the rebase will be aborted.¬
#¬

man git-rebase(1)

The interactive mode is meant for this type of workflow:

1. have a wonderful idea
2. hack on the code
3. prepare a series for submission
4. submit

where point 2. consists of several instances of [either]
 
+ regular use
  1. finish something worthy of a commit
  2. commit
+ independent fixup
  1. realize that something does not work
  2. fix that
  3. commit it"

First of all, please note:

If you remove a line here THAT COMMIT WILL BE LOST.

And then:

However, if you remove everything, the rebase will be aborted.

okay, moving on to the good stuff

rebase -i has a thousand uses

make many commits, but push just one

reword 9852e66 start a feature
squash d2b069a oh yeah add the specs
squash 52ee076 fix broken integration feature
squash e8c3194 no wait, change the feature to actually work

rearrange and group commits

reword 52ee076 fix broken integration feature
squash e8c3194 no wait, remove it instead
reword d2b069a oh yeah add the specs
reword 9852e66 start a feature

conceal own idiocy

edit d2b069a do something good, but also commit s3 keys
pick 52ee076 struggle with something difficult
reword e8c3194 [lurid frustration-fueled profanity]

Programmer Poetry B

"Faster than his tongue did make offence his -i did heal it up..." -W. Shakespeare

an extra page to hide the comment bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment