Removing a patch from a commit in git
dave at thesmithfam.org
Wed Mar 16 21:18:25 MDT 2011
Found it in man git-rebase (the operative search phrase was "splitting a git commit"):
In interactive mode, you can mark commits with the action "edit". However, this does not necessarily mean that git rebase expects the result of this edit to be exactly one commit. Indeed, you can undo the commit, or you can add other commits. This can be used to split a commit into two:
• Start an interactive rebase with git rebase -i <commit>^, where <commit> is the commit you want to split. In fact, any commit range will do, as long as it contains that commit.
• Mark the commit you want to split with the action "edit".
• When it comes to editing that commit, execute git reset HEAD^. The effect is that the HEAD is rewound by one, and the index follows suit. However, the working tree stays the same.
• Now add the changes to the index that you want to have in the first commit. You can use git add (possibly interactively) or git gui (or both) to do that.
• Commit the now-current index with whatever commit message is appropriate now.
• Repeat the last two steps until your working tree is clean.
• Continue the rebase with git rebase --continue.
On Mar 16, 2011, at 8:54 PM, Dave Smith wrote:
> Using git, I have a local commit to which I accidentally added a patch. I would like to remove that patch now, and create a separate commit for that patch. I have not yet pushed my changes to origin.
> I have been unable to find how to do this on Google. I can easily remove a patch from the index (git reset), but what about a patch that's already been committed? I've tried "git rebase -i HEAD^", which lets me amend and squash prior commits, but what about splitting a commit into two?
More information about the PLUG