git 某次提交补丁的生成与应用 (patch)

时间:2022-11-11 18:44:29


Android制作patch:

因为基于Android4.4的代码开发,但是framework层还没有建立branch, 不能直接提交,那么其它依赖这里的同事要用,怎么办呢,就可以打patch,然后把patch发给需要用的同事,他们在本地应用patch就可以了。(但是有个问题,下次你再更新代码的时候,这些patch就会被取消了,需要重新应用)


使用gitformat-patch生成所需要的patch:

# git format-patch -s1bbe3c8c197a35f79bfddaba099270a2e54ea9c7

please replace the hash code with your repo previous commit.

then you can find the patch under repo directory.

then mail your patch to configuration admin. 


# gitformat-patch -M master       // 当前分支所有超前master的提交

# gitformat-patch -s 4e16             // 某次提交以后的所有patch, --4e16指的是SHA1ID

# gitformat-patch -1                 //  单次提交
# git format-patch -3                  //从master往前3个提交的内容,可修改为你想要的数值
# gitformat-patch –n 07fe          // -n指patch数,07fe对应提交的名称, 某次提交(含)之前的几次提交

gitformat-patch -s --rootorigin     // 从origin到指定提交的所有patch

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

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


git am 

http://blog.csdn.net/mliubing2532/article/details/7577905

http://blog.csdn.net/yuyin86/article/details/8087057