git format-patch的使用【转】

本文转载自: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
例子:提交历史如下
[email protected]:/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"

时间: 2024-08-14 10:07:13

git format-patch的使用【转】的相关文章

git 打patch方法

git对比svn有很多优势,这里就不多说了,这里主要讨论打patch的方法. 1.由于打patch的时候一般是将别人的比较,想直接输入到自己的文件 2.采用web的git服务器查看别人的提交记录: 例如如下形式: diff --git a/mediatek/custom/common/hal/audioflinger/Audio_Customization_Common.h b/mediatek/custom/common/hal/audioflinger/Audio_Customization

Git的Patch功能

Git的Patch功能 UNIX世界的软件开发大多都是协作式的,因此,Patch(补丁)是一个相当重要的东西,因为几乎所有的大型UNIX项目的普通贡献者,都是通过 Patch来提交代码的.作为最重要的开源项目之一,Linux,也是这样的.普通开发者从软件仓库clone下代码,然后写入代码,做一个Patch, 最后用E-mail发给Linux Kernel的维护者就好了.Git最初作为Linux的版本控制工具,提供了透明.完整.稳定的Patch功能. 我们先介绍一下Patch是什么.如果一个软件有

步骤:用git提交patch,并发送邮件列表

一. 先配置git send-mail 的 smtp服务器:1. 安装git-email:# apt-get install git git-core git-email 修改gitconfig文件:vim ~/.gitconfig [color] ui = auto [commit] template = -/.commit_template [user] name = *** email = ***@***.com [alias] pretty = log --branches --remo

[Git] Use git add --patch for better commit history and mitigating bugs

Let's split our changes into separate commits. We'll be able to check over our changes before staging them all from the terminal. Then, we'll see the positive effect it has on our commit history. git add --patch 1. Then in the cmd, we can type 's' st

如何使用git 生成patch

1,下载代码 git clone git://git.kernel.org/pub/scm/linux/kernel/git/padovan/bluetooth-next-2.6.git cd bluetooth-next-2.6 2,修改代码 vi drivers/bluetooth/btusb.c 3,把代码添加到git管理仓库 git add drivers/bluetooth/btusb.c 4,提交修改 git commit -m "Added atheros3012 Chip Fir

如何使用git 生成patch 和打入patch 标签: gitpatch【转】

本文转载自:http://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用git 生成patch 给到我们,那我们就需要把客户给到patch 打入到我们的project ,基于这样一个场景,我把git 如何生成patch 和如何打入patch 做总结   生成patch 的方法:(我这里描述的生成patch 是根据commit 记录生成的) 1.例如首先先通过git lo

如何使用git 生成patch 和打入patch【转】

本文转载自:http://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用git 生成patch 给到我们,那我们就需要把客户给到patch 打入到我们的project ,基于这样一个场景,我把git 如何生成patch 和如何打入patch 做总结   生成patch 的方法:(我这里描述的生成patch 是根据commit 记录生成的) 1.例如首先先通过git lo

git diff patch

如何生成patch:修改一个地方,然后git diff > xxx.patch 就会生成一个patch文件,这里的关键似乎是, 源文件的某个模块的版本要和线上发布的最新版本要一致,这样patch才会被官方采纳. git diff --help就会激活一个帮助页面git xxx --help 如何采用patch下载patch文件到当前文件夹,保持环境文件和线上一致,然后git apply -v xxx.patchrm -rf xxx.patch touch .gitignorevi .gitign

git 生成patch和应用patch【转】

本文转载自:http://www.jianshu.com/p/814fb6606734 1.在git源码目录下执行 1.1.两个commit间的修改(包含两个commit) git format-patch <r1>..<r2>如:git format-patch d77aaac74845435744c49ae65511d9e1be79ed5c...046ee8f8423302f5070ca81b4e246516e919cd7a -o patch 1.2.单个commit git

[Practical Git] Format commit history with git log arguments

When running the git log command, we can pass in options as arguments toformat the data shown for each commit. In this lesson, we show how to use the oneline, decorate, graph, stat, and p options with git log. Show it oneline: git log --oneline git l