如何使用本地提交生成git补丁

时间:2012-11-02 09:46:36

标签: git

我正在为开源项目的开发做出贡献,该项目使用git作为源代码的存储库。

在对源代码进行一些修改后,我想生成一个包含我的签名(电子邮件地址和我的名字)的补丁,并将其发送给开源项目维护者。

我该怎么做?

2 个答案:

答案 0 :(得分:6)

1)从git存储库下载源代码:

git clone git://address.of.repository/project/ /folder/path/on/my/computer

2)对源代码进行一些修改。可以在项目中添加新文件/文件夹

3)为git commit signature设置你的电子邮件地址和你的名字:

git config --global user.name "Your Name"
git config --global user.email you@example.com

执行此操作后,您可以使用以下命令修复用于此提交的标识:

git commit --amend --reset-author

4)在提交更改之前。我们必须将新文件/文件夹添加到本地git存储库:

源代码的项目文件夹

git add <Newfolder>
git add <Newfile>

4)然后在本地提交修改:

源代码的项目文件夹

commit -a

这将打开一个交互窗口

您可以检查提交是否已在以下位置检测到已编辑的文件和新文件:

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   bin/Makefile.am
#       modified:   configure.ac
#       new file:   src/new.c

commit -a窗口下,您必须为修改输入评论

然后使用 Ctrl + O (WriteOut)然后Enter保存您的提交,您的提交将立即保存

然后使用 Ctrl + X 退出commit -a窗口(退出)

5)现在您可以使用以下命令生成补丁:

源代码的项目文件夹

git format-patch -1

这将生成一个名为0001-...-...-.. .patch

的补丁文件

如果您想使用signed-off-by生成补丁,只需添加-s

git format-patch -1 -s

答案 1 :(得分:0)

注意:关于git format-patch部分,您将(git 2.0.x / git 2。1,2014年第3季度)添加文件中定义的签名。

commit 7022650

Jeremiah Mahler (jmahler)

format-patch:添加“--signature-file=<file>”选项

  

为format-patch添加一个选项,用于从文件中读取签名。

$ git format-patch -1 --signature-file=$HOME/.signature
  

配置变量format.signaturefile也可用于将其设为默认值。

$ git config format.signaturefile $HOME/.signature
$ git format-patch -1