Initialize new git repo with a blank commit


It is useful to have a completely empty commit as the first commit. This is the command to do that:

GIT_AUTHOR_NAME='nil' \
GIT_AUTHOR_EMAIL='[email protected]' \
GIT_COMMITTER_NAME='nil' \
GIT_COMMITTER_EMAIL='[email protected]' \
GIT_AUTHOR_DATE='1970-01-01 00:00:01' \
GIT_COMMITTER_DATE='1970-01-01 00:00:01' \
git commit --no-gpg-sign --allow-empty -m 'NIL'

The hash for this commit should always be:

1bd23f7d074d57faf0913d7ce3ca84204bc67cee

source

I discovered that there is actually a built-in hidden commit that can be used for similar purposes.

4b825dc642cb6eb9a060e54bf8d69288fbee4904

source

Date: 2021-01-03, Updated: 2022-01-06

Tags:  git

Share: