通过git format-patch 、 git diff 、git apply 三个命令,可以生成patch和打入patch,用于在多个git仓库间传递代码的情况。
比如不想提交代码,但是要把代码传给其他协作者,就很适合用这个方式。
git format-patch
1 2 3 4 5 6 7 8 9 10 11
| # 把当前没push的提交都打成一个patch git format-patch origin
# 把commitid1 和 commitid2 间的提交打成一个patch git format-patch commitid1..commitid2
# 把最近3个提交打成一个patch git format-patch -3
# 把包含commitid在内和之前的共2个提交打成一个patch git format-patch commitid -2
|
git diff
1 2 3
| # 把git diff 的输出内容写入本地,直接作为一个patch文件 git diff > ./pathToSave
|
git apply
1 2
| # 打入patch git apply xxx.patch
|