A long time ago (2014!), [WayBack] Great tutorial on how to split older Git commits: http://bit.ly/1rE72cI – should be used with care, but this can be a lifesaver and a really useful trick… – Ilya Grigorik – Google+ pointed me the below tutorial.
It has been in my drafts since then, but recently I found it back when I needed to rebase unpushed commits. Indeed it’s a great tutorial!
Executing the git rebase --interactive
concepts can be tricky as they are on a way higher level than regular git work. So sometimes you want to exit vim
notifying git
to stop the current action. The easiest way I found was this vim command I found at [WayBack] How to abort a git rebase in interactive editor (thanks [WayBack] Telmo Costa!):
:cx
Via the tutorial, I also bumped into a few advanced git add
features:
Another very powerfull feature is
git add -p
a.k.a.git add --patch
which allows you to stage parts (or hunks) of a file.[WayBack] git add -p: The most powerful git feature you’re not using yet
You can go even further with
git add --interactive
as this blog post shows:
Back to the tutorial:
[WayBack] Going back in time to split older commits by thoughtram
Rebasing in Git allows you to go back in time to split older commits. In this article we’ll explore how to do exactly that!
git rebase –interactive
Before the tutorial explains how to amend git commits, it covers these git rebase --interactive
commands:
- pick
- reword
- edit
- squash
- fixup
Note that squash
will combine the commit on that line with the commit on the line above it.
There is one more little trick: to limit the number of commits (that’s normally limited to the unpushed ones), add like HEAD~4
which limits it to 4 commits.
Finally you can even use this for cherry picking, which I need to put on my research list: [WayBack] git: obtain the benefits of git rebase --interactive
for cherry picks – Stack Overflow
Further reading:
- [WayBack] Git Interactive Rebase, Squash, Amend and Other Ways of Rewriting History
- [WayBack] About Git rebase – User Documentation
- [WayBack] About Git rebase – User Documentation
- [WayBack] Git rebase -i | Atlassian Git Tutorial
- [WayBack] Git – Rewriting History
- [WayBack] Git – git-rebase Documentation
–jeroen