git patch 使用

1使用git format-patch生成所需要的patch:
当前分支所有超前master的提交:
git format-patch -M master
某次提交以后的所有patch:
git format-patch 4e16                --4e16指的是commit名
从根到指定提交的所有patch:
git format-patch                          --root 4e16
某两次提交之间的所有patch:
git format-patch 365a..4e16      --365a和4e16分别对应两次提交的名称
某次提交(含)之前的几次提交:
git format-patch –n 07fe             --n指patch数,07fe对应提交的名称
故,单次提交即为:
git format-patch -1 07fe
git format-patch生成的补丁文件默认从1开始顺序编号,并使用对应提交信息中的第一行作为文件名。如果使用了-- numbered-files选项,则文件名只有编号,不包含提交信息;如果指定了--stdout选项,可指定输出位置,如当所有patch输出到一个文件;可指定-o <dir>指定patch的存放目录;


2应用patch:
先检查patch文件:git apply --stat newpatch.patch
检查能否应用成功:git apply --check  newpatch.patch
打补丁:git am --signoff < newpatch.patch

(使用-s或--signoff选项,可以commit信息中加入Signed-off-by信息)

 

如果应用patch出现问题:参考git am PATCH 失败的处理方法http://blog.csdn.net/sunnylgz/article/details/7660638

 

参考资料:

git-format-patch(1) - Linux man page http://linux.die.net/man/1/git-format-patch

How to create and apply a patch with Git http://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git

 

原文:http://blog.csdn.net/sunnylgz/article/details/7661920

posted on 2014-12-19 14:59  veins  阅读(550)  评论(0编辑  收藏  举报

导航