The answers to How to modify existing, unpushed commits? describe a way to amend previous commit messages that haven't yet been pushed upstream. The new messages inherit the timestamps of the original commits. This seems logical, but is there a way to also re-set the times?
相关问题
- mySQL alter table on update, current timestamp
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- How to convert from Timestamp to Mongo ObjectID
- Emacs shell: save commit message
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- BFG Repo Cleaner – Alternative to Fresh Clone
This changes the date (timestamp) for the last commit
git commit --amend --date "Thu May 28 18:21:46 2015 +0530"
Use
git filter-branch
with an env filter that sets GIT_AUTHOR_DATE and GIT_COMMITTER_DATE for the specific hash of the commit you're looking to fix.This will invalidate that and all future hashes.
Example:
If you wanted to change the dates of commit
119f9ecf58069b265ab22f1f97d2b648faf932e0
, you could do so with something like this:Just do
git commit --amend --reset-author --no-edit
. For older commits, you can do an interactive rebase and chooseedit
for the commit whose date you want to modify.Then amend the commit with
--reset-author
and--no-edit
to change the author date to the current date:Finally continue with your interactive rebase:
Building on theosp's answer, I wrote a script called
git-cdc
(for change date commit) that I put in myPATH
.The name is important:
git-xxx
anywhere in yourPATH
allows you to type:That script is in bash, even on Windows (since Git will be calling it from its msys environment)
With that, you can type:
That would reset author/commit date of the commit before HEAD (
@~
) to the specified date.That would reset author/commit date of the commit before HEAD (
@~
) to the same hour, but 2 days ago.Ilya Semenov mentions in the comments:
You can do an interactive rebase and choose edit for the commit whose date you would like to alter. When the rebase process stops for amending the commit you type in for instance:
Afterwards you continue your interactive rebase.
UPDATE (in response to the comment of studgeek): to change the commit date instead of the author date:
The lines above set an environment variable GIT_COMMITTER_DATE which is used in amend commit.
Everything is tested in Git Bash.
The following bash function will change the time of any commit on the current branch.
Be careful not to use if you already pushed the commit or if you use the commit in another branch.