git打补丁
一、patch和diff的区别
Git 提供了两种补丁方案,一是用git diff生成的UNIX标准补丁.diff文件,二是git format-patch生成的Git专用.patch 文件。
.diff文件:只是记录文件改变的内容,不带有commit记录信息,多个commit可以合并成一个diff文件。
.patch文件:带有记录文件改变的内容,也带有commit记录信息,每个commit对应一个patch文件。
二、创建patch文件的常用命令
1、某次提交(含)之前的几次提交
git format-patch 【commit sha1 id】-n
n指从sha1 id对应的commit开始算起n个提交。
2、某个提交的patch
git format-patch 【commit sha1 id】 -1
3、某两次提交之间的所有patch
git format-patch 【commit sha1 id】..【commit sha1 id】
三、创建diff文件的常用命令
1、某两次提交之间的所有差异
git diff 【commit sha1 id】 【commit sha1 id】 > 【diff文件名】
四、应用patch和diff
1、检查patch/diff是否能正常打入
git apply --check 【path/to/xxx.patch】
git apply --check 【path/to/xxx.diff】
2、打入patch/diff
git apply 【path/to/xxx.patch】
git apply 【path/to/xxx.diff】
本文转载自简书文章:https://www.jianshu.com/p/ec04de3f95cc

浙公网安备 33010602011771号