threads / discuss / 18598

How do I force git to forget about merging a binary file that is to stay deleted on the target branch?

Subject: How do I force git to forget about merging a binary file that is to stay deleted on the target branch?

## tl;dr

7 messages between Mar 28, 2009 and Mar 28, 2009.

replies: 6people: 4as markdown or json

Brent Goodrick· Mar 28, 2009, 05:26 UTC · lore
Hi,

How do I commit a merge but force git to forget about merging one file that I don't want on the target branch, when it is binary, and when it was changed on the source branch, but was deleted on the target branch (and should stay deleted on the target branch)?

The details: I am merging a "work" branch into a "home" branch. There is one file called "TimeSheets/Timesheet Exempt.XLS" that is binary. I don't want that file on the "home" branch, but do want it on the "work" branch. I had made an editing change to that file on the "work" branch, along with a bunch of other changes I do want to merge into the "home" branch. But no matter what I do, I can't force git to forget about that "TimeSheets/Timesheet Exempt.XLS" file.

I've tried various flavors of git-checkout and git-reset to no avail. This is what I see at the very last before I gave up:

Here is what I'm left with:
,----
| $ : gitw status
| TimeSheets/Timesheet Exempt.XLS: needs merge
| # On branch home
| # Changes to be committed:
| #   (use "git reset HEAD <file>..." to unstage)
| #
| <snipped out other files I do want to commit>
| #
| # Changed but not updated:
| #   (use "git add <file>..." to update what will be committed)
| #   (use "git checkout -- <file>..." to discard changes in working directory)
| #
| #	unmerged:   TimeSheets/Timesheet Exempt.XLS
| #
| $ : gitw commit -m "merge from work"
| TimeSheets/Timesheet Exempt.XLS: needs merge
| TimeSheets/Timesheet Exempt.XLS: unmerged
(49a49bd9de154daa8ca6cff3cfb550d0dd1b4519)
| TimeSheets/Timesheet Exempt.XLS: unmerged
(8de60b8b6827ef1f80921f6d35b574a56683bfdd)
| error: Error building trees
`----
Any help anyone can provide is greatly appreciated.

Thanks, Brent

Nanako Shiraishi· Mar 28, 2009, 10:23 UTC · re: Brent Goodrick · lore

Re: How do I force git to forget about merging a binary file that is to stay deleted on the target branch?

Quoting Brent Goodrick <bgoodr@gmail.com>:
> How do I commit a merge but force git to forget about merging one file
> that I don't want on the target branch, when it is binary, and when it
> was changed on the source branch, but was deleted on the target branch
> (and should stay deleted on the target branch)?
I think the standard answer is "you don't".
Instead of using only two branches ('home' and 'work'), you use one common branch (perhaps 'master') that is meant to hold the changes and files that are sharable between two places, and maintain two branches ('home' and 'work') that are forked from the common branch. You treat them as if they are release branches and employ the "Never merging back" workflow (see gitster's journal around middle of January this year).
At home (or at work), you record your changes that are also relevant to the other place to the common branch ('master'), and you record changes that are specific to the location to either 'home' or 'work'. And merge 'master' to 'home' and 'work' as necessary, but never merge 'home' nor 'work' to anything else.
-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
Brent Goodrick· Mar 28, 2009, 14:29 UTC · re: Nanako Shiraishi · lore

Re: How do I force git to forget about merging a binary file that is to stay deleted on the target branch?

On Sat, Mar 28, 2009 at 3:23 AM, Nanako Shiraishi <nanako3@lavabit.com> wrote:
> I think the standard answer is "you don't".

Thanks, but unfortunately, that won't work for me, since I have too many commits with useful history that would get lost if I started over and set up the work and home branches that are branched separately off of master. Also the "work" fileset and the "home" fileset are 80% the same; its the 20% that causes me puzzlement each time I want to merge changes made on one branch onto the other.

bg
Elijah Newren· Mar 28, 2009, 12:47 UTC · re: Brent Goodrick · lore

Re: How do I force git to forget about merging a binary file that is to stay deleted on the target branch?

Hi,
On Fri, Mar 27, 2009 at 11:26 PM, Brent Goodrick <bgoodr@gmail.com> wrote:
Show 15 quoted lines
> How do I commit a merge but force git to forget about merging one file
> that I don't want on the target branch, when it is binary, and when it
> was changed on the source branch, but was deleted on the target branch
> (and should stay deleted on the target branch)?
>
> The details: I am merging a "work" branch into a "home" branch.  There
> is one file called "TimeSheets/Timesheet Exempt.XLS" that is binary.
> I don't want that file on the "home" branch, but do want it on the
> "work" branch.  I had made an editing change to that file on the
> "work" branch, along with a bunch of other changes I do want to merge
> into the "home" branch. But no matter what I do, I can't force git to
> forget about that "TimeSheets/Timesheet Exempt.XLS" file.
>
> I've tried various flavors of git-checkout and git-reset to no
> avail. This is what I see at the very last before I gave up:

You can resolve this merge conflict by running $ git rm TimeSheets/Timesheet\ Exempt.XLS

which will make git delete the file from your working copy and the index, at which point you can then make a commit that does not include this file.

Show 27 quoted lines
> Here is what I'm left with:
>
> ,----
> | $ : gitw status
> | TimeSheets/Timesheet Exempt.XLS: needs merge
> | # On branch home
> | # Changes to be committed:
> | #   (use "git reset HEAD <file>..." to unstage)
> | #
> | <snipped out other files I do want to commit>
> | #
> | # Changed but not updated:
> | #   (use "git add <file>..." to update what will be committed)
> | #   (use "git checkout -- <file>..." to discard changes in working directory)
> | #
> | #     unmerged:   TimeSheets/Timesheet Exempt.XLS
> | #
> | $ : gitw commit -m "merge from work"
> | TimeSheets/Timesheet Exempt.XLS: needs merge
> | TimeSheets/Timesheet Exempt.XLS: unmerged
> (49a49bd9de154daa8ca6cff3cfb550d0dd1b4519)
> | TimeSheets/Timesheet Exempt.XLS: unmerged
> (8de60b8b6827ef1f80921f6d35b574a56683bfdd)
> | error: Error building trees
> `----
>
> Any help anyone can provide is greatly appreciated.
Brent Goodrick· Mar 28, 2009, 14:46 UTC · re: Elijah Newren · lore

Re: How do I force git to forget about merging a binary file that is to stay deleted on the target branch?

On Sat, Mar 28, 2009 at 5:47 AM, Elijah Newren <newren@gmail.com> wrote:
> You can resolve this merge conflict by running
> $ git rm TimeSheets/Timesheet\ Exempt.XLS
Much appreciated! That works.
Thanks for your and Nanako's help!
bg
Junio C Hamano· Mar 28, 2009, 15:07 UTC · re: Elijah Newren · lore

Re: How do I force git to forget about merging a binary file that is to stay deleted on the target branch?

Elijah Newren <newren@gmail.com> writes:
Show 23 quoted lines
> On Fri, Mar 27, 2009 at 11:26 PM, Brent Goodrick <bgoodr@gmail.com> wrote:
>> How do I commit a merge but force git to forget about merging one file
>> that I don't want on the target branch, when it is binary, and when it
>> was changed on the source branch, but was deleted on the target branch
>> (and should stay deleted on the target branch)?
>>
>> The details: I am merging a "work" branch into a "home" branch.  There
>> is one file called "TimeSheets/Timesheet Exempt.XLS" that is binary.
>> I don't want that file on the "home" branch, but do want it on the
>> "work" branch.  I had made an editing change to that file on the
>> "work" branch, along with a bunch of other changes I do want to merge
>> into the "home" branch. But no matter what I do, I can't force git to
>> forget about that "TimeSheets/Timesheet Exempt.XLS" file.
>>
>> I've tried various flavors of git-checkout and git-reset to no
>> avail. This is what I see at the very last before I gave up:
>
> You can resolve this merge conflict by running
> $ git rm TimeSheets/Timesheet\ Exempt.XLS
>
> which will make git delete the file from your working copy and the
> index, at which point you can then make a commit that does not include
> this file.

But is this what you really want to do? After doing such a "remove it" merge resolution at Home, wouldn't merging it back to Work remove the file?

Brent Goodrick· Mar 28, 2009, 15:21 UTC · re: Junio C Hamano · lore

Re: How do I force git to forget about merging a binary file that is to stay deleted on the target branch?

On Sat, Mar 28, 2009 at 8:07 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 10 quoted lines
>> You can resolve this merge conflict by running
>> $ git rm TimeSheets/Timesheet\ Exempt.XLS
>>
>> which will make git delete the file from your working copy and the
>> index, at which point you can then make a commit that does not include
>> this file.
>
> But is this what you really want to do?  After doing such a "remove it"
> merge resolution at Home, wouldn't merging it back to Work remove the
> file?

Yes, and I've not told the full story. Each time I do a merge in between the two branches, I have a script that resets certain files that I don't want cross-pollinated between the two branches. Then I do the commit. Most of the time (on non-binary files, and/or on files I only change on the work branch and not on the home branch), this works just fine.

My desire to avoid doing the above drove my earlier post asking whether there as a facility to exclude certain files from participating in merges. But the answer was "no" to that, hence my ad hoc workaround above.

bg

← back to recent threads