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

Re: How to pull only a few files from one branch to another?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jan 24, 2007, 04:18 UTC
Message-ID
<Pine.LNX.4.64.0701232012450.3606@woody.linux-foundation.org>
In-Reply-To
<Pine.LNX.4.64.0701231937310.3606@woody.linux-foundation.org>
On Tue, 23 Jan 2007, Linus Torvalds wrote:
Show 10 quoted lines
> 
>      If you have just one simple merge-base, you'd do something like
> 
> 	git merge-one-file \
> 		$(git merge-base HEAD other):filename \
> 		HEAD:filename \
> 		other:filename \
> 		filename
> 
>      (where those last three things are just the file mode)

That comment made no sense. I removed the file modes entirely, and forgot to remove the comment. It turns out that you can just drop the file modes entirely from the invocation of least the current "git-merge-one-file", so I did that, to keep it cleaner and simpler.

Anyway, the way "git merge-one-file" works, you pass it:
 - the SHA1 of the "base object"
	$(git merge-base HEAD other):filename
 - the SHA1 of the "current branch version of the file"
	HEAD:filename
 - the SHA1 of the "other branch version of the file"
	other:filename
 - the filename as you want the end result to be in the index
	filename
 - normally, you'd pass the file modes for the three cases too
	0644 0644 0644
   but those are the ones I skipped because the shell script actually only 
   uses them to see if they are different (so dropping them means that it 
   all works fine - the empty arguments are all the same).

but additionally, since "git merge-one-file" expects to be in the middle of a real merge (and not just some faked-out single-file merging thing) it also expects the index to be populated in stage2 with the current branch version of the file - which it won't be outside of a merge. Which is why it ends up complaining.

It would be kind of cool to have the whole "merge-recursive" logic (which can handle multiple ancestors etc - unlike the above) able to do this, but that's a whole 'nother kettle of fish.

			Linus
Previous: Linus TorvaldsNext: Johannes Schindelin
Message 3 of 18 in “How to pull only a few files from one branch to another?”
  1. Bill LearJan 24, 2007
  2. Linus TorvaldsJan 24, 2007
  3. Linus TorvaldsJan 24, 2007
  4. Johannes SchindelinJan 24, 2007
  5. Johannes SchindelinJan 24, 2007
  6. Bill LearJan 24, 2007
  7. Yann DirsonJan 24, 2007
  8. Jakub NarebskiJan 24, 2007
  9. Yann DirsonJan 24, 2007
  10. Jakub NarebskiJan 24, 2007
  11. Linus TorvaldsJan 24, 2007
  12. Daniel BarkalowJan 24, 2007
  13. Bill LearJan 24, 2007
  14. Shawn O. PearceJan 24, 2007
  15. Andy WhitcroftJan 24, 2007
  16. Junio C HamanoJan 24, 2007
  17. Jakub NarebskiJan 24, 2007
  18. Daniel BarkalowJan 24, 2007

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.