I would like to create a commit in a Git repository, but have the name and email associated with the author in the commit be different from the information usually associated with me.
I'd also like to have the timestamp on the commit be something different than my current local time.
I know that I can rewrite my project's history after committing to change this information. But I haven't made the commit yet. Is there some way to change this information at the time I make the commit?
To change the author of the commit, use git commit --author
:
git commit -m "A commit with a different author" --author="Your name here <[email protected]>"
To change the date of the commit, use git commit --date="YYYY-MM-DD HH:MMxm
:
git commit -m "A commit made to celebrate Christmas" --date="2015-12-25 12:00am"
These options can be combined:
git commit -m "Ho ho ho" --author="Santa Claus <[email protected]>" --date="2015-12-25 12:00am"
The git merge
command doesn't have --author
and --date
options. To change the date and author of a merge command, first make the merge regularly:
git merge other_branch
Then, as long as a merge commit was created, you can use git commit --amend
before pushing to change the merge commit's metadata:
git commit --amend --author=... --date=...
You can also set the appropriate environment variables during your commit. From the documentation:[1]
The final creation of a Git commit [...] uses these environment variables as its primary source of information, falling back to configuration values only if these aren't present.
GIT_AUTHOR_NAME
is the human-readable name in the "author" fieldGIT_AUTHOR_EMAIL
is the email for the "author" fieldGIT_AUTHOR_DATE
is the timestamp used for the author fieldGIT_COMMITTER_NAME
sets the human name for the "committer" fieldGIT_COMMITTER_EMAIL
is the email address for the "committer" fieldGIT_COMMITTER_DATE
is used for the timestamp in the "committer" fieldExample:
GIT_AUTHOR_NAME="foo" GIT_AUTHOR_EMAIL="bar" git commit -m "baz"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With