git-commit with date in the past

When setting up the git repository for VRM I wanted to preserve the project development history, but I hadn't used any real VCS tool back then, I just used to make timed backups with a scheme like this:

$ ls -1

Well, fortunately git is flexible enough to allow commits with a date in the past, let's see how... after a little digression.

A simple, but wise, design decision in git (and which any serious SCM made) is the distinction between the Author and the Committer concepts, this allows to record the authorship of a change even if the author doesn't have commit rights to the code base repository. If I contribute sporadically to a project there is no need (nor desire) to give me rights to commit the change directly, I just send a patch to the maintainers and they apply it on my behalf, that's obvious, but I still want to figure as the author of that change in the project history, this is often less obvious :).

Every commit in git has both an Author and a Committer, each with three properties:

  • Name
  • Email
  • Date

as explained in git-commit-tree man page.

For my purposes, I wanted to change the Author Date, and in one case also the Author Name and the Author Email, this can be done using some environment variables when calling git, as suggested in this thread:

DATE_STRING="2006-03-28 00:00:00"
AUTHOR_DATE=$(date -d "$DATE_STRING" "+%s %z")

GIT_AUTHOR_NAME="Antonio Ospite" \
GIT_AUTHOR_EMAIL="<my email here>" \
git commit -s -a

If you don't have last modification time in file names there are still chances the filesystem stored them; for the very first version of VRM I did:

DATE_STRING=$(stat "$FILE" | sed -n '/^Modify/ s/^Modify: //p')
AUTHOR_DATE=$(date -d "$DATE_STRING" "+%s %z")

GIT_AUTHOR_NAME="Nikola Radovanovic" \
GIT_AUTHOR_EMAIL="<his email here>" \
git commit -s -a

An ending note, if you realize you did something wrong after you added all your project history in a git repository, you can use the git filter-branch command to fix the history. But that's another story for another time.

CommentsSyndicate content

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the code without spaces.