当前位置:   article > 正文

git format-patch的使用【转】

git format-patch merge

本文转载自:http://blog.chinaunix.net/uid-28621021-id-3487102.html

git format-patch的使用

 
1.在dev1分支上,打出所有dev1分支在master分支基础上的patch
git format-patch master
结果为d1c1.patch ,d1c2.patch
2.在dev1分支上,打出所有dev1分支的所有patch
git format-patch –root dev1
结果为mc1.patch,d1c1.patch ,d1c2.patch
3.在dev2分支上,打出所有dev2分支在master分支基础上的patch
git format-patch master
结果为d2c1.patch ,d2c2.patch
4.在dev2分支上,打出所有dev2分支的所有patch
git format-patch –root dev2
结果为mc1.patch,mc2.patch,mc3.patch,d2c1.patch ,d2c2.patch
5.在dev2分支上,打出所有相对于dev1分支的所有patch
git format-patch –root dev1
结果为 mc2.patch,mc3.patch,d2c1.patch ,d2c2.patch
6.比较两个分支
git diff dev1 dev2
7.比较两个分支中单个文件的区别
git diff dev1 dev2 main.c
8.将所有的commit信息保存在文件中
git log > commit.txt
git log | grep “commit” -A3 >commit.txt 保存commit开始的3行
 
-An after , -Bn before, -Cn(前后n行)
9.将dev1的分支merge到dev2分支
在dev2分支下,git merge --commit dev1
10.找到dev2在master分支上的commitID
git merge-base dev2 master
会显示dev2和master两个分支的共同的commitID


撤消历史提交
1
git revert commit_ID
例子:提交历史如下
ss@ss:/work/test$ git log
commit 70869ac8cc36c05267aad41954f89d068d2d8142
Author: ss 
Date:   Thu Mar 21 20:12:58 2013 +0800

    new a

commit 226e1a70d720f47d21d3664688d9dc34665ba84f
Author: ss 
Date:   Thu Mar 21 20:05:36 2013 +0800

    commit c

commit ff45af7db705904bc49fc09679b2c384ce778d1a
Author: ss 
Date:   Thu Mar 21 20:05:23 2013 +0800

    commit b

commit 76e846f8ee0106840767d5522c7d33d7f752527b      
Author: ss 
Date:   Thu Mar 21 20:05:08 2013 +0800

    commit a

commit 8e7979f6617ae9fc6ae3666002bf17482bd10e28
Author: ss 
Date:   Wed Feb 20 20:06:09 2013 +0800

    Iitial

如果我想撤消
commit 226e1a70d720f47d21d3664688d9dc34665ba84f
Author: ss 
Date:   Thu Mar 21 20:05:36 2013 +0800

    commit c
这笔提交;则使用命令:git revert 226e1a70d720f47d21d3664688d9dc34665ba84f
效果如下:
commit 40f83cb1fa45702ec31bcdd4426580551edfae8e
Author: ss <ss.ss< span="">.com>
Date:   Thu Mar 21 20:13:07 2013 +0800

    Revert "commit c"
    
    This reverts commit 226e1a70d720f47d21d3664688d9dc34665ba84f.
commit 70869ac8cc36c05267aad41954f89d068d2d8142
Author: ss 
Date:   Thu Mar 21 20:12:58 2013 +0800

    new a

commit 226e1a70d720f47d21d3664688d9dc34665ba84f
Author: ss 
Date:   Thu Mar 21 20:05:36 2013 +0800

    commit c

commit ff45af7db705904bc49fc09679b2c384ce778d1a
Author: ss 
Date:   Thu Mar 21 20:05:23 2013 +0800

    commit b

这样在这一比提交的东西将会被撤销
2
若想撤消
commit 70869ac8cc36c05267aad41954f89d068d2d8142
Author: ss 
Date:   Thu Mar 21 20:12:58 2013 +0800

    new a

commit 226e1a70d720f47d21d3664688d9dc34665ba84f
Author: ss 
Date:   Thu Mar 21 20:05:36 2013 +0800

    commit c

commit ff45af7db705904bc49fc09679b2c384ce778d1a
Author: ss 
Date:   Thu Mar 21 20:05:23 2013 +0800

    commit b

这三笔提交
可以用命令
git reset --hard 76e846f8ee0106840767d5522c7d33d7f752527b  这笔ID为commi a
git reset --soft 70869ac8cc36c05267aad41954f89d068d2d8142
git commit -m "cccc"

转载于:https://www.cnblogs.com/zzb-Dream-90Time/p/6728034.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/641165
推荐阅读
相关标签
  

闽ICP备14008679号