Re: merge only some of the changed files?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



fkater@xxxxxxxxxxxxxx wrote:
> If I want to merge branch B into A, however not all of the
> changed files in B, how do I do that?
> 
> In other words: 'git diff --name-only A..B' lists 10 files
> but I want to merge only 5 of them.

First of all, these are not the differences that would be merged: if
you're on A and run 'git merge B', it will merge the changes since the
merge-base(s) of A and B.  Assuming you only have a single merge-base,
this is

  git diff $(git merge-base A B) B

which you can write more conveniently (see man git-diff) as

  git diff A...B

(note the three dots!).

Second, you can't really do a "half merge" because that would be a
lie.  A merge promises to bring all changes from all parents, which
you don't want to do.  You can either split out the relevant changes
from your branch (use e.g. git-cherry-pick or 'git rebase -i' on a new
branch B1 started from B) on the branch, and merge that.  Or you can
do a "squashed merge" of only the files you want by saying e.g.

  git diff A...B -- file1 file2 | git apply

and then committing that with a suitable message.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]