git制作补丁
已提交的修改:
- git format-patch -1 commitid
未提交的修改:
- git diff >> xxx.patch
常用命令:
- git am + patch_file 是专门用于git format-patch 所生成的补丁,使用git am + patch_file会自动commit 并根据patch生成提交记录。
git format-patch HEAD^ #生成最近的1次commit的patch
git format-patch HEAD^^ #生成最近的2次commit的patch
git format-patch HEAD^^^ #生成最近的3次commit的patch
git format-patch HEAD^^^^ #生成最近的4次commit的patch
#生成两个commit间的修改的patch(包含两个commit. 和都是具体的commit号)
git format-patch ..
#指定commit号 //生成指定commit号的补丁
git format-patch -1 commitid
#生成某commit以来的修改patch(不包含该commit)
git format-patch commitid
git format-patch --root #生成从根到r1提交的所有patch
commit号可以使用git log等命令来获取
git应用patch
- git diff 和 git format-patch 生成的补丁文件都可以使用git patch ,git apply来打补丁,但是 git am 仅可以用于git format-patch 生成的补丁。
检查patch文件
- git apply --stat newpatch.patch
检查是否应用成功
- git apply --check newpatch.patch
应用补丁
git am --signoff < newpatch.patch
- (使用-s或--signoff选项,可以commit信息中加入Signed-off-by信息)
git apply与git am的区别:
1.git apply并不会将commit message等打上去,打完patch后需要重新git add和git commit;
2.git am会直接将patch的所有信息打上去,不用重新git add和git commit,author也是patch的author而不是打patch的人