-
Notifications
You must be signed in to change notification settings - Fork 0
Rebasing
Dave Anderson edited this page Aug 1, 2013
·
5 revisions
Rebase changes modifies a series of commits to start from a later commit then they originated from. The common example is when you branch off the master branch and the master branch moves ahead in parallel to your branch work.
# master -> D254644; HEAD -> master
git checkout -b abranch # abranch -> master -> D254644; HEAD -> abranch
git add . # G154547 commit-tree created; G154547.parent -> D143424
git commit -m "abranch work" # abranch -> G154547
git checkout master # HEAD -> master
git add . # J154510 commit-tree created; J154510.parent -> D143424
git commit -m "master work" # master -> J154510
git checkout abranch # HEAD -> abranch
git rebase master # G154547 changes are calculated off of J154510 into new L141211
# L141211.parent -> J154510; abranch -> L141211
git checkout master # HEAD -> master
git merge abranch # master -> L141211
This rebase changes the way the master merged in the branch. What was bound to be a composite merge is now a simple fast-forward merge. It is as if you branched for master after those changes were made to master.
# master -> D254644; HEAD -> master
git checkout -b abranch # abranch -> master -> D254644; HEAD -> abranch
git add . # G154547 commit-tree created; G154547.parent -> D143424
git commit -m "abranch 1" # abranch -> G154547
git add . # J154510 commit-tree created; J154510.parent -> G154547
git commit -m "abranch 2" # abranch -> J154510
git rebase -i
This brings up an interactive interface.
pick G154547 abranch 1
pick J154510 abranch 2
# Rebase G154547..J154510 onto G154547
#
# 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
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
I just want to squash my history together.
pick G154547 abranch 1
s J154510 abranch 2
and save
I'm prompted by a commit message screen
and save M534312 commit-tree created; M534312.parent -> D254644; abranch -> M534312
Now my commits are collapsed into 1 commit.