aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-06-17 12:31:03 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-06-17 12:31:03 +0200
commit3ac8f8d767fea236ae6fcf72f9f3f23e56f4828a (patch)
tree9f8375165f25aa5dcfbc5a1f2efecc30b0fdaf51
parent168616fbd3ff91253f5a3e0df8d4efc140f6dc03 (diff)
Add section on history cleanup
-rw-r--r--cheatsheet.txt69
1 files changed, 69 insertions, 0 deletions
diff --git a/cheatsheet.txt b/cheatsheet.txt
index 92bee2e..20894f7 100644
--- a/cheatsheet.txt
+++ b/cheatsheet.txt
@@ -67,6 +67,75 @@ Rebasing
git rebase origin[/master]
git push --tags origin
+History Cleanup
+
+ This is the overall process for cleaning up the history in a feature
+ branch before merging it into master. The goal is to end up with a
+ nice and clean history in master, without any divergences and merges
+ that usually the result of the git merge command.
+
+ Note: make sure you have rerere enabled for this process to work
+ smoothly (~/.gitconfig).
+
+ Note: if you are just learning this procedure, make a local backup
+ copy of your repository in case things go badly and you need to
+ start from scratch.
+
+ To achieve this we first merge any unmerged changes that may be on
+ master and then rebase the whole thing on master. The end result of
+ this step is a history that first has all the commits that are from
+ master followed by all the commit from the feature branch (in other
+ words, master is now a prefix of our history which means we can
+ fastforward-only (--ff-only) merge this history into it):
+
+ git cout feature
+ git merge master
+ git rebase master
+
+ At this stage, run gitk and verify that you now have a linear history
+ that starts with master.
+
+ The second step is to clean up the commit history of our feature
+ branch since it may have "dirty", work-in-progress commits. This may
+ involve squashing several commits into one, rewording commit messages,
+ and possibly reordering the commits. The swiss army knife for this
+ is the interactive git rebase:
+
+ git rebase -i HEAD~<N>
+
+ Where <N> is the number of commits you would like to cleanup. Generally,
+ if you want to work on all the commits on this feature branch run gitk
+ and count the number of commits from the top to the first commit that
+ is on master (and if you know a better way to achieve the same result,
+ let me know). That is your <N>.
+
+ Note also that the order of commits in the resulting edit file will
+ be the reverse of what you see in gitk.
+
+ Once in the edit file, use commands to squash, reword, or reorder
+ the history (note that squashing several commits automatically
+ means rewording the commit message). Note also that you can re-run
+ this command multiple times. For example, you can squash some
+ commits, then examine the history (with gitk), then squash some
+ more, etc.
+
+ Finally, once the history is cleaned up, we can merge it into
+ master:
+
+ git cout master
+ git merge --ff-only feature
+
+ Verify with gitk everything looks good on master and push:
+
+ git push
+
+ It is also a good idea to delete the feature branch, both locally
+ and on the origin:
+
+ git br -d feature
+ git push origin :feature
+
+
Submodules
git config --global status.submoduleSummary true