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 :
- in A_dir: git format-patch <commit_id> -1 # to generate a patch file, say 0001.patch
- 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.shtob/git-gui.shcan be applied to the file in the working treemodules/git-gui/git-gui.shby runninggit apply --directory=modules/git-gui.
