I was e-mailed a git patch on "code1" created with format-patch. Problem is that the co-worker who sent it apparently has a different directory structure than I have. My directory looks like
/home
/mydir
/project
/code1
/src
/obj
/bin
/code2
/code3
and my .git is sitting in /project. He apparently only has /code1 and that's where his .git is sitting. However, his /code1
does look exactly like my /code1
.
I try to apply the patch with git am, and it fails with the error
error: src/foo.c: does not exist in index
error: src/bar.c: does not exist in index
Patch failed at <new commit message>.
I have tried using the --directory flag, but I get the same error, only with the directory names changed. Is there any way to do this.
BTW, I anticipate someone is going to flag this as a duplicate of this question, but the situation there was somewhat different and the solution given there has not helped me. Thanks.
git am
is designed to re-create the original commit from the patch.
To re-create the original commit (with the same hash ID and everything), the change made in your repository must be bit-for-bit identical to the change made in his repository. This would naturally require that your repository have the same layout (and parent commits leading to this point) as those in the patch.
Since your repository has a different structure, you cannot use git am
to apply the patch. You can instead use git apply
, but you will have to fuss with the path names a bit. Note that, like the standard patch utility, the -p number
option lets you remove path components, but that won't help in this case. In this case, you will need to add some path components, so you want the --directory=path
option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With