git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: removing a bad commit

From
Johan Herland <johan@herland.net>
Date
May 2, 2013, 10:33 UTC
Message-ID
<CALKQrgdomY_JTzkAaVYsShtLRmc342xEprhkbiiNPitAcWJi+A@mail.gmail.com>
In-Reply-To
<CAH_OBifxVOaFMXCthm+r30GNaqrsLRoBE-wvzkeKVxw7R2gGFA@mail.gmail.com>
On Thu, May 2, 2013 at 12:15 PM, shawn wilson <ag4ve.us@gmail.com> 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, <johan@herland.net>
www.herland.net
Previous: shawn wilson
Message 2 of 2 in “removing a bad commit”
  1. shawn wilsonMay 2, 2013
  2. Johan HerlandMay 2, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.