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

Merging back from master but keeping a subtree

From
SBSteinar Bang <sb@dod.no>
Date
Sep 17, 2011, 07:49 UTC
Message-ID
<87y5xn8v6z.fsf@dod.no>
I have a long lived branch that changes a directory and its
subdirectory, ie. 
 top/middle/mydirectory

Now I want to merge in an updated remoterepo/master and keep everything from that master, except for mydirectory and its subdirectory, where I would like to keep everything from my branch.

I tried a regular merge, and used
 git checkout --ours
 git add
and 
 git checkout --theirs
 git add
as appropriate on all conflicts.

But the result didn't build, and the build errors don't make much sense, so I think they are caused by "successful" merges giving bad results.

Is there a better way to do this?

Would it be possible to unstage the already staged files and apply the "checkout --ours" and "checkout --theirs", and then git add on the checked out files?

Even that would be clumsy... I would have preferred something like
 git checkout --theirs top
 git checkout --ours top/middle/mydirectory
 git add-only-those-modified-wrt-my-branch
Thanks!
- Steinar
Next: Jeff King
Message 1 of 3 in “Merging back from master but keeping a subtree”
  1. Steinar BangSep 17, 2011
  2. Jeff KingSep 18, 2011
  3. Steinar BangNov 16, 2011

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.