GIT: change commit date to author date

kevingoos picture kevingoos · Feb 16, 2015 · Viewed 14.7k times · Source

Is it possible to change the commit date from my commit to the author date?

I adapted some commits and now the dates are all the same. I want to set it back to the old dates (or the author dates). Is this possible?

I am using Sourcetree so I have the git command line but I am not a pro at that. My external repository is bitbucket.

Answer

jsphpl picture jsphpl · Jul 26, 2016

Short Answer:

git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"'

Explanation:

filter-branch lets you rewrite your git history. It can apply transformations to each commit or filter out commits based on certain criteria. See git filter-branch --help for a comprehensive description and usage instructions.

--env-filter allows you to set the environment variables that are present during the creation of the new history. It is evaluated for each commit separately.