1

I have a file in my git repository which sometimes receives bug fixes in another git repository. I would like to be able to pull those commits into my repo.

For example:

project_a/
  /.git
  /src/somefile.cpp

project_b/
  /.git
  /utils/converters/apples/bananas/src/somefile.cpp

I would like to pull in commits from project_b to project_a for somefile.cpp.

zfedoran
  • 2,986
  • 4
  • 22
  • 25

2 Answers2

3

In case you have files with the same name but in different folders (lets assume that you had project_b merged into a subdir) then you have to do the cherry pick in the following fashion

git cherry-pick project_b/master --strategy=subtree
RaB
  • 1,545
  • 13
  • 16
2

You can add project_b as a remote and then fetch and cherry-pick from it. Try something like this:

git remote add project_b /path/to/project_b/
git fetch project_b

Now you can cherry pick from project_b. If the commit you want is at the tip of project_b's master branch, just do

git cherry-pick project_b/master

Alternatively, you can bypass the remote fetching/cherry-picking stuff and just patch directly from project_b like so:

git --git-dir=/path/to/project_b/.git format-patch -k -1 \
--stdout <commit SHA> somefile.cpp | git am -3 -k

(Adapted from this answer.)

Community
  • 1
  • 1
peterjmag
  • 6,041
  • 1
  • 30
  • 27