removing a bad commit

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

removing a bad commit

From: shawn wilson <hidden>
Date: 2016-06-15 22:57:06

I've got a commit that was done about a week ago that I want to remove
(preferably remove and rewrite history as it's in a branch and it
doesn't need to be in this branch until the branch is working) but if
a reverse patch is the only way, i'll go with it.

Re: removing a bad commit

From: Johan Herland <hidden>
Date: 2016-06-15 22:57:06

On Thu, May 2, 2013 at 12:15 PM, shawn wilson [off-list ref] wrote:
I've got a commit that was done about a week ago that I want to remove
(preferably remove and rewrite history as it's in a branch and it
doesn't need to be in this branch until the branch is working) but if
a reverse patch is the only way, i'll go with it.
Whether or not you should rewrite history depends on whether the bad
commit has been shared with anybody else. If others have started
working on top of your history, they will not enjoy it if you rewrite
that history and force them to rebase their work accordingly. In that
case, your best bet is a reverse patch: "git revert $bad_commit_sha1"

Otherwise, if the bad commit exists nowhere else but your own repo,
then you can do an interactive rebase to remove the bad commit: On the
branch with the bad commit: "git rebase -i $bad_commit_sha1^" (the
trailing caret ^ is important). This will launch a text editor listing
your last commits starting with your bad commit. Delete the first line
containing your bad commit, and save/exit the editor. Git will now
replay all your last commits except for the bad commit. If any of the
later commits touch the same stuff as the bad commit did, Git might
stop the rebase because of conflicts when it replays those patches. In
this case, fix the conflicts, add the file, and "git rebase
--continue". Repeat until all commits have been replayed and the
rebase is finished.

Hope this helps,

...Johan

-- 
Johan Herland, [off-list ref]
www.herland.net
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help