threads / discuss / 27248

removing a commit from a branch

Subject: removing a commit from a branch

## tl;dr

8 messages between May 4, 2011 and May 5, 2011.

replies: 7people: 5as markdown or json

Gergely Buday· May 4, 2011, 08:35 UTC · lore
Hi there,

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.

Cheers
- Gergely
Jeff King· May 4, 2011, 08:45 UTC · re: Gergely Buday · lore

Re: removing a commit from a branch

On Wed, May 04, 2011 at 10:35:08AM +0200, Gergely Buday wrote:
> 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.

Removing it will involve rewriting history, which can create headaches for people who have built on that history (they will need to rebase their commits on the rewritten history). But if that's OK, then the command you want is filter-branch. See "git help filter-branch"; in particular, the EXAMPLES section contains commands to do exactly what you want.

-Peff
Gergely Buday· May 4, 2011, 08:55 UTC · re: Jeff King · lore

Re: removing a commit from a branch

> Removing it will involve rewriting history, which can create headaches
> for people who have built on that history (they will need to rebase
> their commits on the rewritten history).
I did not push to any other repo yet, so this should be OK.
- Gergely
Peter Krefting· May 4, 2011, 09:17 UTC · re: Gergely Buday · lore

Re: removing a commit from a branch

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.
-- 
\\// Peter - http://www.softwolves.pp.se/
Dirk Süsserott· May 4, 2011, 17:53 UTC · re: Peter Krefting · lore

Re: removing a commit from a branch

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
Dirk Süsserott· May 4, 2011, 19:12 UTC · re: Dirk Süsserott · lore

Sorry, completely off-topic. I've a mailer problem (was: Re: removing a commit from a branch)

Sorry, I know, this is no Thunderbird board, but I guess other people use this client as well.

When I write a message, it wraps at col 72 (or so). When I see my post in the list, it isn't wrapped at all. Only one long line per paragraph. That's inconvenient for the list and I'd like to avoid that. How do YOU do that?

I'm using Mozilla Thunderbird 3.1.10 for Windows (which is the latest, I think).

Again, I'm sorry about posing such an off-topic and non-git question, but probably someone has the same prob (or -- even better -- has had resolved it).

Cheers,
     Dirk
Øyvind A. Holm· May 4, 2011, 21:28 UTC · re: Dirk Süsserott · lore

Re: Sorry, completely off-topic. I've a mailer problem (was: Re: removing a commit from a branch)

2011/5/4 Dirk Süsserott <newsletter@dirk.my1.cc>:
Show 14 quoted lines
> Sorry, I know, this is no Thunderbird board, but I guess other people
> use this client as well.
>
> When I write a message, it wraps at col 72 (or so). When I see my post
> in the list, it isn't wrapped at all. Only one long line per
> paragraph. That's inconvenient for the list and I'd like to avoid
> that. How do YOU do that?
>
> I'm using Mozilla Thunderbird 3.1.10 for Windows (which is the latest,
> I think).
>
> Again, I'm sorry about posing such an off-topic and non-git question,
> but probably someone has the same prob (or -- even better -- has had
> resolved it).

There is a section on how to set up Thunderbird and other mail clients in Documentation/SubmittingPatches in the git.git repository which you can read here:

  http://repo.or.cz/w/git.git/blob_plain/HEAD:/Documentation/SubmittingPatches

Regards, Øyvind

Dirk Süsserott· May 5, 2011, 18:59 UTC · lore

Re: Sorry, completely off-topic. I've a mailer problem

Am 04.05.2011 22:03 schrieb Phil Hord:
Show 25 quoted lines
> On 05/04/2011 03:12 PM, Dirk Süsserott wrote:
>> Sorry, I know, this is no Thunderbird board, but I guess other people
>> use this client as well.
>>
>> When I write a message, it wraps at col 72 (or so). When I see my post
>> in the list, it isn't wrapped at all. Only one long line per
>> paragraph. That's inconvenient for the list and I'd like to avoid
>> that. How do YOU do that?
> 
> 
> Options > Format > Plain text only
> 
> However, your emails are being sent wrapped as you see them originally.
>   But in your email headers is this line:
> 
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> The "format=flowed" is convincing Thunderbird to unwrap your lines when
> you view them in Thunderbird. The raw text of your emails look fine.
> (In Thunderbird, examine the raw email with Ctrl-U.)
> 
> More on f=f: http://joeclark.org/ffaq.html
> 
> Phil
> 
Thank you, Phil and Øyvind,

I now configured my Thunderbird to do it right (I hope). My next post will tell ...

Dirk

← back to recent threads