{"thread":{"id":"23080","subject":"merge only some of the changed files?","startedAt":"2010-03-19T13:40:28Z","lastAt":"2010-03-19T14:01:57Z","messageCount":3,"participants":["fkater@googlemail.com","Michael J Gruber","Thomas Rast"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"137213","messageId":"20100319134028.GA2318@comppasch2","threadId":"23080","inReplyTo":null,"subject":"merge only some of the changed files?","fromName":"fkater@googlemail.com","fromEmail":"fkater@googlemail.com","sentAt":"2010-03-19T13:40:28Z","receivedAt":"2010-03-19T13:40:28Z","isPatch":false,"sender":{"key":"fkater@googlemail.com","avatar":null},"body":"Hi all,\n\nI am quite new to git.\n\nIf I want to merge branch B into A, however not all of the\nchanged files in B, how do I do that?\n\nIn other words: 'git diff --name-only A..B' lists 10 files\nbut I want to merge only 5 of them.\n\nThank You\n Felix\n"},{"id":"137215","messageId":"4BA3825E.1070700@drmicha.warpmail.net","threadId":"23080","inReplyTo":"20100319134028.GA2318@comppasch2","subject":"Re: merge only some of the changed files?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-03-19T13:55:42Z","receivedAt":"2010-03-19T13:55:42Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"fkater@googlemail.com venit, vidit, dixit 19.03.2010 14:40:\n> Hi all,\n> \n> I am quite new to git.\n> \n> If I want to merge branch B into A, however not all of the\n> changed files in B, how do I do that?\n> \n> In other words: 'git diff --name-only A..B' lists 10 files\n> but I want to merge only 5 of them.\n\nIf you are sure you don't want to merge the changes to them later on,\nyou can do the following while on branch A\n\n# perform the merge but do not commit\ngit merge --no-commit B\n# overwrite the files you want to keep with their version from A\ngit checkout HEAD -- file1 file2\n# commit the merge result\ngit commit\n\nCheers,\nMichael\n"},{"id":"137217","messageId":"201003191501.58045.trast@student.ethz.ch","threadId":"23080","inReplyTo":"20100319134028.GA2318@comppasch2","subject":"Re: merge only some of the changed files?","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-03-19T14:01:57Z","receivedAt":"2010-03-19T14:01:57Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"fkater@googlemail.com wrote:\n> If I want to merge branch B into A, however not all of the\n> changed files in B, how do I do that?\n> \n> In other words: 'git diff --name-only A..B' lists 10 files\n> but I want to merge only 5 of them.\n\nFirst of all, these are not the differences that would be merged: if\nyou're on A and run 'git merge B', it will merge the changes since the\nmerge-base(s) of A and B.  Assuming you only have a single merge-base,\nthis is\n\n  git diff $(git merge-base A B) B\n\nwhich you can write more conveniently (see man git-diff) as\n\n  git diff A...B\n\n(note the three dots!).\n\nSecond, you can't really do a \"half merge\" because that would be a\nlie.  A merge promises to bring all changes from all parents, which\nyou don't want to do.  You can either split out the relevant changes\nfrom your branch (use e.g. git-cherry-pick or 'git rebase -i' on a new\nbranch B1 started from B) on the branch, and merge that.  Or you can\ndo a \"squashed merge\" of only the files you want by saying e.g.\n\n  git diff A...B -- file1 file2 | git apply\n\nand then committing that with a suitable message.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"}]}