- r1 - Initial prototype
- r2 - Added 10 lines of code, need to take baby on a walk. brb.
- r3 - I know it doesn't compile, yet, but need to go to sleep. I'll finish implementing toString() tomorrow.
- r4 - Compiles but haven't tested the code, still need to fix that weird bug in activateSkyNet().
- r5 - Version 2
Preferably, I would like the commit history to look like
- r1 - Initial prototype
- r2 - Added activateSkyNet()
- r3 - Fix null reference in activateSkyNet()
I'd love to have the ability to take commits r2, r3, and r4 and merge them into one patch; it would allow me to see the code changes associated with activateSkyNet() feature. In a collaborative OSS project, the ability to manage your commits makes it easier to submit one clean patch to the project maintainers.
Fortunately, Git allows you to do this with the `rebase -i` (rebase interactively) command. Let's see how we can combine a series of commits into one single commit. We will start from:
commit f6bed0d862007a3eab3eafc23a92623349d46ac7
Author: John
Date: Mon Jul 4 11:00:31 2011 -0700
Version 4
commit acd3830ce5d450424299e6deb3846a89cd3dfaa4
Author: John
Date: Mon Jul 4 11:00:19 2011 -0700
Version 3
commit f268a9dbe474f928ebbb34a60533d7ad930f852d
Author: John
Date: Mon Jul 4 11:00:08 2011 -0700
Version 2
commit 41a5f4995fd12312ed286010f3708105a7682f3c
Author: John
Date: Mon Jul 4 10:55:57 2011 -0700
Initial import
The rebase -i command will allow us to do this
git rebase -i 41a5f49
In your editor...
r f268a9d @Laptop Version 2
f acd3830 @Laptop Version 3
f f6bed0d @Laptop Version 4
# Rebase 41a5f49..f6bed0d onto 41a5f49
#
# 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
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
Git will prompt for a new commit message
Now the status of the repo. You only see 2 commits. The previous commit 2 to 4 have been merged into one clean commit.
Run rebase with
Version 2 - Clean
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Not currently on any branch.
# Changes to be committed:
# (use "git reset HEAD^1 ..." to unstage)
#
# modified: test.py
#
Now the status of the repo. You only see 2 commits. The previous commit 2 to 4 have been merged into one clean commit.
commit 223ad1926cdda7336f1728739770efc4a2f971f8
Author: John
Date: Mon Jul 4 11:00:08 2011 -0700
Version 2 - Clean
commit 41a5f4995fd12312ed286010f3708105a7682f3c
Author: John
Date: Mon Jul 4 10:55:57 2011 -0700
Initial import
Example 2
commit d083d8c1a19e97201477be649d03ce429e5e4319
Author: John
Date: Mon Jul 4 11:42:50 2011 -0700
Version 4
commit a9d3c77c9f31587d187e0e86e34fd6b0163bd02d
Author: John
Date: Mon Jul 4 11:42:27 2011 -0700
Version 3
commit d9b16d0534b586b70a16655257633727cd70f4d4
Author: John
Date: Mon Jul 4 11:42:19 2011 -0700
Version 2
commit 4ed968376ff2ef44b68d92c177e58c6cc2139990
Author: John
Date: Mon Jul 4 11:42:11 2011 -0700
Version 1
commit a5cf612f3a041aec3373b6af417a986e251af05a
Author: John
Date: Mon Jul 4 11:41:58 2011 -0700
Initial import
Run rebase with
git rebase -i 41a5f49
In your editor...
r d9b16d0 Version 2
f a9d3c77 Version 3
p d083d8c Version 4
# Rebase 4ed9683..d083d8c onto 4ed9683
#
# 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
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
So “Version 3” and “Verison 2” will be combined into one commit. Commit “Version 4” will be left unchanged.
Combined commits "Version 2" and "Version 3"
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Not currently on any branch.
# Changes to be committed:
# (use "git reset HEAD^1 ..." to unstage)
#
# modified: test.py
#
Final result:
jcheng@jcheng-desktop:~/tmp/gittut1/1$ git log
commit 661963557c161b4c9d019c817944e83435a9893a
Author: John
Date: Mon Jul 4 11:42:50 2011 -0700
Version 4
commit 78c6af526a4c3a24eb5536520238388d531ce71a
Author: John
Date: Mon Jul 4 11:42:19 2011 -0700
Combined commits "Version 2" and "Version 3"
commit 4ed968376ff2ef44b68d92c177e58c6cc2139990
Author: John
Date: Mon Jul 4 11:42:11 2011 -0700
Version 1
commit a5cf612f3a041aec3373b6af417a986e251af05a
Author: John
Date: Mon Jul 4 11:41:58 2011 -0700
Initial import
No comments:
Post a Comment