检查patch/diff是否能正常打入:
git apply --check 【path/to/xxx.patch】
git apply --check 【path/to/xxx.diff】
打入patch/diff:
git apply 【path/to/xxx.patch】
git apply 【path/to/xxx.diff】
或者
git am 【path/to/xxx.patch】
- [#]$git am 'Testpatch.diff'
Applying: Google Test patch
error: patch failed: Test.java:49
error: Test.java: patch does not apply
Patch failed at 0001 Google Test patch
Use 'git am --show-current-patch' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
强行应用不冲突的部分:
- [#]$git apply --reject Testpatch.diff'
Checking patch Test.java...
error: while searching for:
error: patch failed: Test.java:49
Hunk #4 succeeded at 71 (offset -4 lines).
Hunk #5 succeeded at 87 (offset -4 lines).
Applying patch Test.java with 1 reject...
Hunk #1 applied cleanly.
Hunk #2 applied cleanly.
Rejected hunk #3.
Hunk #4 applied cleanly.
一般其他的文章都会告诉你,“这时候在当前的目录下针对patch fail的文件会生成fileX.rej.这些文件的内容就是发生冲突的地方, 手动修正就好.”,但是却没有解释怎么处理冲突,我来详细写一下吧:
-
[#]$gedit Test.java 根据Test.java.rej将这里未merge的部分,直接修改到Test.java里
Test.java Test.java.rej
删除rej文件后,将修正好的fileX.c add到缓冲区里去:
- [#]$git rm -rf Test.java.rej
rm 'Test.java.rej'
- [#]$git add .
关键的一步,如果还想保留原作者,那么就要使用git am --continue命令(或者git am --resolved)再推一次。
- [#]$git am --continue
Applying: Google Test patch
- [#]$git commit --amend
[aa 6890c5e2c1] Google Test patch
Author: google.name <xxxx@google.com>
Date: Wed Sep 18 11:27:52 2019 -0700
1 file changed, 173 insertions(+), 53 deletions(-)
拓展内容: