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

Re: merge only some of the changed files?

From
Thomas Rast <trast@student.ethz.ch>
Date
Mar 19, 2010, 14:01 UTC
Message-ID
<201003191501.58045.trast@student.ethz.ch>
In-Reply-To
<20100319134028.GA2318@comppasch2>
fkater@googlemail.com wrote:
Show 5 quoted lines
> 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
Previous: Michael J Gruber
Message 3 of 3 in “merge only some of the changed files?”
  1. fkater@googlemail.comMar 19, 2010
  2. Michael J GruberMar 19, 2010
  3. Thomas RastMar 19, 2010

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.