András Gyömrey
András Gyömrey

Reputation: 1829

Override author on git merge

Is there an option like --author of git-commit for git-merge?

We maintain a staging environment where some changes must be performed. Some limitations make us to use only one linux user to access staging environment.

Anyway, we are a small team with cooperative initiative and we tell when doing commits, which one is the author using the --author git-commit option. However, some times we need to merge from other branches which result in a non-ff merge. This implies a commit is performed when doing this merge.

Which would be the best way to specify the author manually for the merge commit in this case?

Upvotes: 27

Views: 13639

Answers (4)

q9f
q9f

Reputation: 11824

You can --amend the authorship afterwards if you already did the merge. like that:

git checkout master
git merge my_branch
git commit --amend --author="My Nick <[email protected]>"
git push origin master

This works as desired and adds the specified author to the merge commit. No magic. :)

Upvotes: 17

Bombe
Bombe

Reputation: 83847

First, prevent the merge from creating the commit:

git merge --no-commit …

Then, do the commit manually:

git commit --author="A. U. Thor <[email protected]>"

Upvotes: 34

Clemens Heuberger
Clemens Heuberger

Reputation: 59

An alternative could be to set the GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables:

GIT_AUTHOR_NAME="A. U. Thor" GIT_AUTHOR_EMAIL="[email protected]" git merge ...

Upvotes: 5

kan
kan

Reputation: 28951

Try git merge --no-commit ... and then git commit --author ...

Upvotes: 6

Related Questions