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

  • [#]$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

 

然后将修正好的fileX.c add到缓冲区里去.

  • [#]$git add .
  • [#]$git rm -rf Test.java.rej 

rm 'Test.java.rej'

 

关键的一步,如果还想保留原作者,那么就要使用git am --continue命令再推一次。

  • [#]$git am --continue

Applying: Google Test patch

  • [#]$git commit --amend

[aa 6890c5e2c1] Google Test patch
 Author: google.name
 Date: Wed Sep 18 11:27:52 2019 -0700
 1 file changed, 173 insertions(+), 53 deletions(-)

你可能感兴趣的:(软件编程)