====== 'git' Environment and Overriding Settings ======
===== Overriding Default Settings =====
==== Environment Variables To Specify Author And Committer ====
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 name
* **''GIT_AUTHOR_EMAIL''** for the author's email address
* **''GIT_COMMITTER_NAME''** for the committer's human-readable name
* **''GIT_COMMITTER_EMAIL''** for the committer's email address
For example
export GIT_AUTHOR_NAME=~~codedoc:"Martin Burnicki"~~
export GIT_AUTHOR_EMAIL=~~codedoc:"martin.burnicki@burnicki.net"~~
export GIT_COMMITTER_NAME=${GIT_AUTHOR_NAME}
export GIT_COMMITTER_EMAIL=${GIT_AUTHOR_EMAIL}
git commit -m ~~codedoc:"My sudo commit"~~
or for a single command:
GIT_AUTHOR_NAME=~~codedoc:"Martin Burnicki"~~ GIT_AUTHOR_EMAIL=~~codedoc:"martin.burnicki@burnicki.net"~~ GIT_COMMITTER_NAME=${GIT_AUTHOR_NAME} GIT_COMMITTER_EMAIL=${GIT_AUTHOR_EMAIL} git commit -m ~~codedoc:"My sudo commit"~~
\\
==== Environment Variables To Specify Commit Dates ====
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.
\\
==== Using A Non-Standard Name For The Local '.git' Directory ====
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=~~codedoc:.git-repo-1~~ gitk &
git ~~codedoc:clean:--~~git-dir=~~codedoc:.git-repo-1~~ fetch
\\
===== Working With 'git' Dates =====
''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:
/* Don't use codedoc here, this would create real email address links */
commit 7590a8c4a730ec889798497db259e91ef701caec
Author: Martin Burnicki
Date: Fri Mar 29 12:44:04 2019 +0100
whereas e.g. ''gitk'' shows **both the author and commiter date**:
/* Don't use codedoc here, this would create real email address links */
Author: Martin Burnicki 2019-03-29 12:44:04
Committer: Martin Burnicki 2019-03-29 12:44:04
\\
==== Overriding 'git' Dates ====
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
* **Working with dates in Git**\\
[[https://alexpeattie.com/blog/working-with-dates-in-git]]
\\
=== The '--date' Parameter ===
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 ~~codedoc:"My commit message."~~ ~~codedoc:clean:--~~date=~~codedoc:"2023-04-01 13:45"~~
However, the **commiter date** is still set to the current time.
\\
=== Environment variables GIT_AUTHOR_DATE and GIT_COMMITTER_DATE ===
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=~~codedoc:"2023-04-01 13:45"~~ GIT_COMMITTER_DATE=~~codedoc:"2023-04-01 15:45"~~ git commit -m ~~codedoc:"My commit message."~~
sets the dates to specified but different values, while
GIT_AUTHOR_DATE=~~codedoc:"2023-04-01 13:45"~~ GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}" git commit -m ~~codedoc:"My commit message."~~
sets them both to the same value.
\\
==== Check In An Existing Old File With Its Original Date ====
When old files from an existing project are to be imported into a newly created 'git' repo,
[[#Environment Variables To Specify Author And Committer|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 ~~codedoc:my-old-file~~
GIT_AUTHOR_DATE=~~codedoc:"2016-06-11 16:29:04"~~ GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}" git commit -m ~~codedoc:"Add my-old-file."~~
----
--- //Martin Burnicki [[martin.burnicki@burnicki.net]] 2020-03-18//