7

I have three branches (let's call them master, testing, and feature). All three are shared, so I cannot rebase any of them without causing problems for others. Currently, all three branches have diverged (none is a fast-forward), so eventually some merging will need to done, since rebasing is not an option.

For the moment, though, I would like to pull in the Makefile from testing into feature, since feature was split off from master, and the Makefile was added in testing. I do not want to merge in any other changes between the two branches, however.

My understanding is that if I just git-add Makefile to feature, this will cause merge conflicts when I merge feature back into testing (and then master), especially if I make any further additions to the Makefile in my feature branch.

I could do git-cherry-pick; however, there were multiple commits to the Makefile in testing, and I assume there's a better way than trying to cherry-pick all of those commits into feature.

chimeracoder
  • 20,648
  • 21
  • 60
  • 60

1 Answers1

12

You can just do a

git checkout branch_name <path(s)>

This can load a specific file but you can also use wildcards and directories

Note that:

  • Paths are relative
  • The path makes that git does not switch branches, so you can just commit after gettihg the file
Dirk
  • 2,348
  • 17
  • 23
  • Wow - I've used checkout both for switching to a commit by it's SHA, and on a file revert back to HEAD, but I didn't realize that you could combine the two that way. This is rather obvious in retrospect now, but thanks! – chimeracoder Mar 23 '12 at 05:19