Git sign off previous commits?

后端 未结 8 535
没有蜡笔的小新
没有蜡笔的小新 2020-12-12 11:24

I was wondering how to sign(-s) off previous commits that I have made in the past in git?

相关标签:
8条回答
  • 2020-12-12 12:08

    If anyone still looking for a better-automated way of signing off commits.

    Try this:

    git rebase --exec 'git commit --amend --no-edit -n -S' -i commit-hash
    

    This will rebase everything till the commit-hash (X commits)

    Then git push -f is required to push back the change in history back to remote

    0 讨论(0)
  • 2020-12-12 12:09

    An interactive rebase with the -S flag will do the job.

    Let's say you need to sign off the last n commits (make sure to checkout the latest of those n commits).

    Run:

    $ git rebase -S -i HEAD~n
    
    # The `-S` flag is important.
    # It tells Git to sign the following commits.
    

    This gives a list of the last n commits.

    Now, change pick to edit prefix for all the commits you want to sign.

    Once done, close the editor. A new editor will open with everything about the commit.

    Since nothing needs to be changed in the commit, save the file and exit the editor. You can also change the commit message while at it.

    Repeat this for other commits.

    To push the latest history, git push remote branch -f.

    Warning

    There's one gotcha - it can rewrite your commits.

    If you sign a 4-month old commit, it might overwrite its date and make it look like it was created today. So, not recommended when you want to preserve your commit history.

    0 讨论(0)
提交回复
热议问题