In an environment where it is not possible to save author and committer information permanently, a couple of environment variables can be set to specify this information:
GIT_AUTHOR_NAME
for the author's human-readable nameGIT_AUTHOR_EMAIL
for the author's email addressGIT_COMMITTER_NAME
for the committer's human-readable nameGIT_COMMITTER_EMAIL
for the committer's email addressFor example
export GIT_AUTHOR_NAME="Martin Burnicki" export GIT_AUTHOR_EMAIL="martin.burnicki@burnicki.net" export GIT_COMMITTER_NAME=${GIT_AUTHOR_NAME} export GIT_COMMITTER_EMAIL=${GIT_AUTHOR_EMAIL} git commit -m "My sudo commit"
or for a single command:
GIT_AUTHOR_NAME="Martin Burnicki" GIT_AUTHOR_EMAIL="martin.burnicki@burnicki.net" GIT_COMMITTER_NAME=${GIT_AUTHOR_NAME} GIT_COMMITTER_EMAIL=${GIT_AUTHOR_EMAIL} git commit -m "My sudo commit"
Environment variables can also be used to override commit and author dates. See chapter "Check In An Existing Old File With Its Original Date" for details.
By default, git
saves project information in a hidden directory named .git
.
However, if a project contains files from several git
repos, e.g. scripts
in /usr/local/bin/
from different repos, it is possible to override
the default name .git
by some other name, using environment variables,
or command line parameters. E.g.:
GIT_DIR=.git-repo-1 gitk &
git --git-dir=.git-repo-1 fetch
git
commits distinguish between an Author Date and a Commiter Date.
By default both are set to the system date and time which is current when the git commit
command is executed.
git log
only shows the author date by default:
commit 7590a8c4a730ec889798497db259e91ef701caec Author: Martin Burnicki <martin.burnicki@burnicki.net> Date: Fri Mar 29 12:44:04 2019 +0100
whereas e.g. gitk
shows both the author and commiter date:
Author: Martin Burnicki <martin.burnicki@burnicki.net> 2019-03-29 12:44:04 Committer: Martin Burnicki <martin.burnicki@burnicki.net> 2019-03-29 12:44:04
This can be useful e.g. if you have a couple of old versions of a file and want to put them into
a git
repo to improve future tracking, but want to keep the original, historic dates.
More details and examples can be found in
The –date
parameter can be used with the commit command to set the author date to the specified date and time, e.g.:
git commit -m "My commit message." --date="2023-04-01 13:45"
However, the commiter date is still set to the current time.
If both the author date and the commiter date are to be specified, the environment variables
GIT_AUTHOR_DATE
and GIT_COMMITTER_DATE
can be used to specify both dates, e.g.
GIT_AUTHOR_DATE="2023-04-01 13:45" GIT_COMMITTER_DATE="2023-04-01 15:45" git commit -m "My commit message."
sets the dates to specified but different values, while
GIT_AUTHOR_DATE="2023-04-01 13:45" GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}" git commit -m "My commit message."
sets them both to the same value.
When old files from an existing project are to be imported into a newly created 'git' repo, environment variables can be used to set the commit dates to the original file date, and thus maintain the original file history.
git add -f my-old-file GIT_AUTHOR_DATE="2016-06-11 16:29:04" GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}" git commit -m "Add my-old-file."
— Martin Burnicki martin.burnicki@burnicki.net 2020-03-18