1.生成Patch
a.查看日志信息,选择要打补丁的版本 git log
b.git format-patch 5fbfa380424a0e048f2cd935a5440151fa1eb6a5 生成补丁 (某次提交之后的所有提交打成一个patch)
format-patch 参数
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
c.切换分支 git branch 查看分支情况 git checkout master 切换到主干分支
d.执行git am 0001-test-patch-S6.patch 想要将补丁打入master分支 由于存在冲突 不能正常打入
e.git apply 0001-test-patch-S6.patch --reject生成冲突文件对比解决冲突
f. git add src/main/resources/zConfig.properties 将最终版本文件添加进patch
g. git am --resolved 解决冲突 git commit 本地提交
h.最终提交 git push
注意:
尽量在每次打补丁时提前 git pull 防止冲突
参考 https://git-scm.com/book/zh/v2