如何使用git interactive rebase签署一系列提交

时间:2014-08-29 14:59:13

标签: git git-rebase git-commit

我想签署我已完成的分支上的所有提交,并希望发送到上游项目(例如通过GitHub上的pull请求)。

我发现的推荐方法是使用

git rebase -i [base-commit]
# Set all commits to "edit"
git commit --amend --signoff  # do this for all commits

如何在一个非交互式命令中自动执行此操作?

2 个答案:

答案 0 :(得分:5)

转而认为git别名可以很好地做到这一点。加入~/.gitconfig

[alias]
  # Usage: git signoff-rebase [base-commit]
  signoff-rebase = "!GIT_SEQUENCE_EDITOR='sed -i -re s/^pick/e/' sh -c 'git rebase -i $1 && while git rebase --continue; do git commit --amend --signoff --no-edit; done' -"

此处还有Gist

你就像git rebase一样使用它;使用pick edit会自动将sed翻转为--no-edit,并确保不会为每次提交都打开编辑器。

答案 1 :(得分:4)

使用Git 2.13(2017年第二季度),不再有" git commit --amend --signoff"需要:
请参阅commit 9f79524(2017年4月18日)和commit 0fb3c4fcommit b7cc705(2017年4月15日)Giuseppe Bilotta (Oblomov)(由Junio C Hamano -- gitster --合并于commit 768c7cb,2017年4月26日)

  

rebase:将--[no-]signoff选项传递给git am

     

这样可以在提交前轻松注销整个补丁集。

git rebase man page现在包括:

--signoff:
  

此标记将传递给' git am'签署所有重新提交的承诺。
  与--interactive选项不兼容。

更新(一年后,2018年5月)" git rebase"已学会尊重" --signoff"使用时的选项 " am"以外的后端(但不是" --preserve-merges")。

  

rebase:扩展--signoff支持

     

允许--signoff--interactive--merge一起使用   在交互模式下,仅提交标记为选择,编辑或重写的提交   将被签署。

     

这个补丁的主要动机是允许一个人运行' git rebase --exec "make check" --signoff'这在准备补丁时很有用   出版系列,比签字更方便   使用另一个--exec命令。

     

此更改还允许--root没有--onto同时使用--signoff--root已支持--onto

它也更强大:

  

rebase -p:如果给出--signoff

,则输出错误      

rebase --preserve-merges不支持--signoff错误输出   而不是只是默默地忽略它,以便用户知道   提交不会被签署。

相关问题