4

I'm looking for a way to write the Signed-off-by: tag automatically when I commit.

I tried configuring it through the .git/config file (Reference). I put these lines of code:

[alias]
    commit = commit -s

This did not work. As commented below, you can not edit git's own alias (like commit).(Reference)

I also tried using the command (Reference): git config --global format.signoff true

Also had no effect. This explains why.

I'm looking for any solution that automatically places the tag and allows me to edit the commit message directly on git, without having to use a system alias.

Community
  • 1
  • 1
Eliseu Egewarth
  • 135
  • 2
  • 9
  • 4
    It is [documented](https://git-scm.com/docs/git-config#git-config-alias) that *"To avoid confusion and troubles with script usage, aliases that hide existing Git commands are ignored."*. You should pick a new name for the alias. – axiac Jan 26 '17 at 19:53
  • 1
    `format.signoff` only matters for patch ([Reference](http://stackoverflow.com/a/15018905/2449905)). To do what you want, see [this answer](http://stackoverflow.com/a/34687806/2449905). – Dan Lowe Jan 26 '17 at 19:57
  • @axiac thank you. Unfortunately I will have to use another alias. – Eliseu Egewarth Jan 27 '17 at 18:21
  • @DanLowe That [answer](http://stackoverflow.com/questions/15015894/git-add-signed-off-by-line-using-format-signoff-not-working/34687806#34687806) is not interesting. I wanted it to automatically change information like: `Signed-off-by: $ {You_ Name} $ {your_email}` To work for other users as well. – Eliseu Egewarth Jan 27 '17 at 18:39
  • [This answer](https://stackoverflow.com/questions/15015894/git-add-signed-off-by-line-using-format-signoff-not-working/46536244#46536244) provides to automatically add signed-off without an alias. – Coiby Aug 01 '22 at 02:46

3 Answers3

4

[Edit made after last comment]

I think if I am guessing correctly then, you cannot alias using words which are 'reserved' words for a git command.

However if you do something like this

[alias]
  ci = commit -s

Then it will do what you want it to do.

  • My intention was to configure directly in git, without having to appeal to the system alias. – Eliseu Egewarth Jan 27 '17 at 18:09
  • @EliseuEgewarth, please review the answer again. –  Jan 27 '17 at 19:23
  • @EliseuEgewarth Just suggesting that the question can be rephrased to say that why git alias doesn't works on some keywords. –  Jan 27 '17 at 19:29
  • my goal was to find an option that would change the command (`git commit` to `git commit -s`), but as it was already [answered](https://git-scm.com/docs/git-config#git-config-alias), that is not possible. The answer to my question has already been given. Thank you. – Eliseu Egewarth Feb 14 '17 at 18:12
1

Use the commits hooks to achieve this
https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks

prepare-commit-msg

The prepare-commit-msg hook is run before the commit message editor is fired up but after the default message is created.

It lets you edit the default message before the commit author sees it.

This hook takes a few parameters: the path to the file that holds the commit message so far, the type of commit, and the commit SHA-1 if this is an amended commit.

This hook generally isn’t useful for normal commits; rather, it’s good for commits where the default message is auto-generated, such as templated commit messages, merge commits, squashed commits, and amended commits.

You may use it in conjunction with a commit template to programmatically insert information.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
-1

You can use commit.gpgSign option

you can add it per repository by issuing the command below in the repo folder:

$ git config commit.gpgSign true

or for all git repository on your machine:

$ git config --global commit.gpgSign true
Dmitry Shvetsov
  • 651
  • 10
  • 19
  • 1
    gpgSign is unrelated to the "sign-off" feature. "sign-off" feature is the lowercase "git commit -s" option, while gpgSign is the uppercase "git commit -S" option. – Étienne Sep 30 '22 at 13:18