本文共 2520 字,大约阅读时间需要 8 分钟。
一般而言,为了保留git log的记录,我们在做patch的时候会使用git format patch的命令来生成一个patch,在应用patch的时候会选择git am来打上patch.一般的patch会包含N个文件的补丁,假设
有其中一个文件发生了conflict,那么am的过程就会停止,这时候需要我们手动去解决冲突,然后才能继续.
git format-patch -N //制作一个补丁,N表示生成几个patch,默认是一笔commit一个patchgit am (--continue | --skip | --abort) PATCH_NAME //打补丁git apply --reject PATCH_NAME //强制应用补丁git add FILE_NAME //添加到缓冲区 1 2 3 4 5
1.>git format-patch -1 生成一个patch:0001-modify-contents.patch,又或许这个patch是别人给你的 1 2 3
2.>git am 0001-modify-contents.patch 出现下面的log,说明am的过程发生了错误 Applying: modify contents error: file1.c: does not match index error: patch failed: file2.c:0 error: file2.c: patch does not apply error: patch failed: file3.c:0 error: file3.c: patch does not apply Patch failed at 0001 modify contents The copy of the patch that failed is found in: .git/rebase-apply/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". 1 2 3 4 5 6 7 8 9 10 11 12 13 14
3.>git status 可以看到下面的log.说明am过程暂时停止了,但是还处在am的对话中. You are in the middle of an am session. (fix conflicts and then run "git am --continue") (use "git am --skip" to skip this patch) (use "git am --abort" to restore the original branch) 1 2 3 4 5 6
4.>git apply --reject 0001-modify-contents.patch 出现下面的log,说明file1,file2,file3发生了冲突,无法自动合并: Checking patch file1.c... error: while searching for: error: patch failed: file1.c:0 Checking patch file2.c... error: while searching for: error: patch failed: file2.c:0 Checking patch file3.c... error: while searching for: error: patch failed: file3.c:0 Applying patch file1.c with 1 reject... Rejected hunk #1. Applying patch file2.c with 1 reject... Rejected hunk #1. Applying patch file3.c with 1 reject... 这时候在当前的目录下针对patch fail的文件会生成fileX.rej.这些文件的内容就是发生冲突的地方, 手动修正就好. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
5.将修正好的fileX.c add到缓冲区里去. >git add . 假设本文件夹下还有一些是untracked的文件的话,还是建议用git add 特定的文件比较好 1 2 3 4
6.>git am --resolved 然后就会显示: Applying: XXXXX. XXXXX就是那笔patch本身的log信息 然后git log 就能看到那笔patch打上去了 1 2 3 4 5 6
转载地址:http://gbzin.baihongyu.com/