简体   繁体   中英

How to 'git-am' apply a patch created with 'git-format-patch --no-prefix'?

I have a reason¹ to create my git commits as patch files using git-format-patch with the --no-prefix option.

This option changes the patch output to not add the git-diff-specific prefixes a/ / b/ in file paths in the patch files. It allows tools like patch to apply the patch files without the need to pass -p1 as argument.

All cool so far. However, it seems that I cannot actually apply them anymore with Git itself (git-am):

$ git am path/to/0001-patch.patch
Applying: <commit message subject>
error: <path>: does not exist in index
Patch failed at 0001
[...]

How do I apply them with git-am now, while maintaining plain patch compatibility?

¹ It allows me to use it as patch files in Bazel without custom patch commands, as you'd need to apply patches with patch -p1 [...] .

git-am passes on a few options to git-apply , including the -p option, which does the same as it does with patch . Ie., apply such patches with -p0 :

git am -p0 path/to/0001-patch.patch

It would have been great if git-format-patch was able to hint git-am within the auxiliary data of the patch file created, that it should apply them without the assumption of a path prefix — just like it can hint git-am with base tree information nowadays (see --base option).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM