git am error: patch failed冲突错误解决

检查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(-)

拓展内容:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值