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

Re: removing a commit from a branch

From
DSDirk Süsserott <newsletter@dirk.my1.cc>
Date
May 4, 2011, 17:53 UTC
Message-ID
<4DC192A0.6010808@dirk.my1.cc>
In-Reply-To
<alpine.DEB.2.00.1105041014480.16939@ds9.cixit.se>
Am 04.05.2011 11:17 schrieb Peter Krefting:
Show 19 quoted lines
> Gergely Buday:
>
>> I have a problematic commit in a series of commits on a branch. It
>> contains adding a large binary file, which I would like to avoid to
>> push to our main repository. How can I remove that from the series of
>> commits? A command-line solution, please, if possible.
>
> If the branch is simple (no merges and such), I'd use "git rebase
> --interactive branchpoint" (where "branchpoint" is where the branch is
> rooted), or "git rebase --interactive problematic^" (where "problematic"
> is the commit you want to edit, note the trailing "^" to start from its
> parent commit).
>
> Then change the "pick" for the problematic commit to "edit", run the
> rebase, fix up the commit by using "git rm" and "git commit --amend"
> when it pauses, and then let it finish using "git rebase --continue".
>
> "git --help rebase" for more information.
>

If your "problematic" commit contains only that "large file" and nothing else, then you'd probably like to remove the whole commit instead of editing it (as Peter described). Just do:

$ git rebase --interactive problematic^
Again, notice the ^ after "problematic"

An editor pops up with the history since problematic's parent, i.e. "problematic" is the first item in the list. Simply delete the line with the "problematic" commit. It should be the first line. Save the file, exit the editor. That's it.

     Dirk
Previous: Peter KreftingNext: Dirk Süsserott
Message 5 of 8 in “removing a commit from a branch”
  1. Gergely BudayMay 4, 2011
  2. Jeff KingMay 4, 2011
  3. Gergely BudayMay 4, 2011
  4. Peter KreftingMay 4, 2011
  5. Dirk SüsserottMay 4, 2011
  6. Sorry, completely off-topic. I've a mailer problem (was: Re: removing a commit from a branch)Dirk Süsserott, May 4, 2011
  7. Øyvind A. HolmMay 4, 2011
  8. Dirk SüsserottMay 5, 2011

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.