Home > Software design >  how can I merge git commit from one repo to another repo?
how can I merge git commit from one repo to another repo?

Time:10-14

Say I have one repo named A, and A has a source file folder A_dir, where I have a <commit_id> on the source files in A_dir Now I have another different repo named B, B has the same source file folder B_dir, is there any ways I can apply <commit_id> in B_dir?

What I tried is :

  1. in A_dir: git format-patch <commit_id> -1 # to generate a patch file, say 0001.patch
  2. switch to B_dir:
    cp A_dir/0001.patch .
    git apply --check 0001.patch
    git apply 0001.patch

But the result is the patch seems not applied, When I use "git status" in B, it only reports:

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        0001.patch    

CodePudding user response:

But the result is the patch seems not applied,

Check first if B_dir is a a subdirectory of a repository.
From git apply man page:

When running from a subdirectory in a repository, patched paths outside the directory are ignored

Make sure to apply the patch from the root folder of the target repository, using the --directory option

Prepend <root> to all filenames.
If a "-p" argument was also passed, it is applied before prepending the new root.

For example, a patch that talks about updating a/git-gui.sh to b/git-gui.sh can be applied to the file in the working tree modules/git-gui/git-gui.sh by running git apply --directory=modules/git-gui.

  • Related