# Git merge selective files

5 messages from 2009-06-09 to 2009-06-09. Participants: joe higton, Avery Pennarun, Alex Riesen, Junio C Hamano.
Thread: https://gitlist.dev/t/19756

## joe higton, 2009-06-09 09:53

Subject: Git merge selective files
Message-ID: <34b359190906090253v653ecc71q6684f4ebff2be59d@mail.gmail.com>
URL: https://gitlist.dev/e/34b359190906090253v653ecc71q6684f4ebff2be59d%40mail.gmail.com

```
Hi,
     I want to merge changes from a branch but only to one file, I
don't want to pick up the changes from other files. I've scoured
google and the docs a bit but I can't find anything useful. Is this
possible?

Ta,
  Joe.

-- 
Gmail is watching you!!!!!!

Please don't publish this email address or use it for anything SPAM
risky. My more public email address is joe@draxil.uklinux.net

```

## Avery Pennarun, 2009-06-09 18:32

Subject: Re: Git merge selective files
Message-ID: <32541b130906091132sc5a647cn5fe0289ff9793cc3@mail.gmail.com>
URL: https://gitlist.dev/e/32541b130906091132sc5a647cn5fe0289ff9793cc3%40mail.gmail.com
In-Reply-To: <34b359190906090253v653ecc71q6684f4ebff2be59d@mail.gmail.com>

```
On Tue, Jun 9, 2009 at 5:53 AM, joe higton<draxil@gmail.com> wrote:
>     I want to merge changes from a branch but only to one file, I
> don't want to pick up the changes from other files. I've scoured
> google and the docs a bit but I can't find anything useful. Is this
> possible?

You might want to try just using

    git diff old-version new-version | patch -p1

(where old-version and new-version are the appropriate commit ids or
branch names or whatever)

And then committing the results.

Have fun,

Avery

```

## Alex Riesen, 2009-06-09 19:35

Subject: Re: Git merge selective files
Message-ID: <81b0412b0906091235g7a65d076l145c3eb3cbbdce3@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0906091235g7a65d076l145c3eb3cbbdce3%40mail.gmail.com
In-Reply-To: <34b359190906090253v653ecc71q6684f4ebff2be59d@mail.gmail.com>

```
2009/6/9 joe higton <draxil@gmail.com>:
> Hi,
>     I want to merge changes from a branch but only to one file, I
> don't want to pick up the changes from other files. I've scoured
> google and the docs a bit but I can't find anything useful. Is this
> possible?

Generally - no. But you can have a merge with only the content
of your choice:

  git merge -s ours --no-commit other

then copy the changes you need manually, and commit.
See the manpage of git merge about "ours" merge strategy.

```

## Avery Pennarun, 2009-06-09 19:39

Subject: Re: Git merge selective files
Message-ID: <32541b130906091239x1c92a1caxd260983a66e8025f@mail.gmail.com>
URL: https://gitlist.dev/e/32541b130906091239x1c92a1caxd260983a66e8025f%40mail.gmail.com
In-Reply-To: <4A2EB575.8050107@workspacewhiz.com>

```
On Tue, Jun 9, 2009 at 3:18 PM, Joshua Jensen<jjensen@workspacewhiz.com> wrote:
> On Tue, Jun 9, 2009 at 5:53 AM, joe higton<draxil@gmail.com> wrote:
>>     I want to merge changes from a branch but only to one file, I
>> don't want to pick up the changes from other files. I've scoured
>> google and the docs a bit but I can't find anything useful. Is this
>> possible?
>
> I like this one:
>
> http://jasonrudolph.com/blog/2009/02/25/git-tip-how-to-merge-specific-files-from-another-branch/

Careful... that *replaces* the files with the ones from the branch.
It doesn't *merge* them.  Although that may be exactly what you want.

And the "'merge --squash' and don't commit the changes you don't want"
option looks okay to me too.

Avery

```

## Junio C Hamano, 2009-06-09 20:54

Subject: Re: Git merge selective files
Message-ID: <7v63f5ku1e.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v63f5ku1e.fsf%40alter.siamese.dyndns.org
In-Reply-To: <32541b130906091239x1c92a1caxd260983a66e8025f@mail.gmail.com>

```
Avery Pennarun <apenwarr@gmail.com> writes:

> And the "'merge --squash' and don't commit the changes you don't want"
> option looks okay to me too.

Whatever you do to prepare the tree contents to suit the desire of the
original request, I think it is essential not to record the result of such
an operation as a merge (because it is not, and it will screw up later
merges).

Use of "merge --squash" in this thread is a very good suggestion.

Good job.

```
