Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use git interactive rebase for signing off a series of commits

I would like to sign off all commits on a branch that I have finished and want to send to an upstream project (e.g. via a pull request on GitHub).

A recommended way I've found is to use

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

How can I do this automatically, in one non-interactive command?

like image 513
nh2 Avatar asked Aug 29 '14 14:08

nh2


Video Answer


2 Answers

With Git 2.13 (Q2 2017), no more "git commit --amend --signoff" needed:
See commit 9f79524 (18 Apr 2017), and commit 0fb3c4f, commit b7cc705 (15 Apr 2017) by Giuseppe Bilotta (Oblomov).
(Merged by Junio C Hamano -- gitster -- in commit 768c7cb, 26 Apr 2017)

rebase: pass --[no-]signoff option to git am

This makes it easy to sign off a whole patchset before submission.

The git rebase man page now includes:

--signoff:

This flag is passed to 'git am' to sign off all the rebased commits.
Incompatible with the --interactive option.


Update (one year later, May 2018) "git rebase" has learned to honor "--signoff" option when using backends other than "am" (but not "--preserve-merges").

rebase: extend --signoff support

Allow --signoff to be used with --interactive and --merge.
In interactive mode only commits marked to be picked, edited or reworded will be signed off.

The main motivation for this patch was to allow one to run 'git rebase --exec "make check" --signoff' which is useful when preparing a patch series for publication and is more convenient than doing the signoff with another --exec command.

This change also allows --root without --onto to work with --signoff as well (--root with --onto was already supported).

It is also more robust:

rebase -p: error out if --signoff is given

rebase --preserve-merges does not support --signoff so error out rather than just silently ignoring it so that the user knows the commits will not be signed off.

like image 200
VonC Avatar answered Oct 10 '22 22:10

VonC


It turns that git aliases can do this quite nicely. Put into your ~/.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' -"

Here's also a Gist for it.

You use it just like git rebase; the picks are automatically flipped to edits using sed and --no-edit makes sure to not open an editor for every single commit.

like image 27
nh2 Avatar answered Oct 10 '22 21:10

nh2