Change the name, email address and / or date for one specific commit * before * committing

I would like to create a commit in the Git repository, but the name and email address associated with the author in commit will be different from the information usually associated with me.

I would also like the timestamp on the commit to be something different from my current local time.

I know that I can rewrite my project history afterwards to change this information. But I have not made a commit yet. Is there a way to change this information during a commit?

+7
git
source share
2 answers

You can also set the appropriate environment variables during commit. From the documentation: [1]

Final creation Git commit [...] uses these environment variables as the main source of information; it returns to configuration values ​​only if they are not there.

  • GIT_AUTHOR_NAME is the human-readable name in the author field
  • GIT_AUTHOR_EMAIL is the email address for the author field.
  • GIT_AUTHOR_DATE is the timestamp used for the author field
  • GIT_COMMITTER_NAME sets the person name for the committer field
  • GIT_COMMITTER_EMAIL - email address for the committer field
  • GIT_COMMITTER_DATE used for the timestamp in the committer field.

Example:

 GIT_AUTHOR_NAME="foo" GIT_AUTHOR_EMAIL="bar" git commit -m "baz" 
+1
source share

To change the author of a commit, use git commit --author :

 git commit -m "A commit with a different author" --author="Your name here < yourEmailHere@includeTheAngleBrackets.com >" 

To change the commit date, 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 parameters can be combined:

 git commit -m "Ho ho ho" --author="Santa Claus < santa@northpole.org >" --date="2015-12-25 12:00am" 

The git merge command has no parameters --author and --date . To change the date and author of a merge command, first merge regularly:

 git merge other_branch 

Then, until the merge git commit --amend has been created, you can use git commit --amend before clicking to change the merge metadata:

 git commit --amend --author=... --date=... 
+7
source share

All Articles