git rebase without changing commit timestamps

git rebase without changing commit timestamps

git rebase change timestamp
git am
git rebase edit commit
git-change commit date
git rebase --edit-todo
git change time of commits
git rebase previous commit
git squash old commits

Would it make sense to perform git rebase while preserving the commit timestamps?

I believe a consequence would be that the new branch will not necessarily have commit dates chronologically. Is that theoretically possible at all? (e.g. using plumbing commands; just curious here)

If it is theoretically possible, then is it possible in practice with rebase, not to change the timestamps?

For example, assume I have the following tree:

master <jun 2010>
  |
  :
  :
  :     oldbranch <feb 1984>
  :     /
oldcommit <jan 1984>

Now, if I rebase oldbranch on master, the date of the commit changes from feb 1984 to jun 2010. Is it possible to change that behaviour so that the commit timestamp is not changed? In the end I would thus obtain:

      oldbranch <feb 1984>
      /
 master <jun 2010>
    |
    :

Would that make sense at all? Is it even allowed in git to have a history where an old commit has a more recent commit as a parent?


git rebase -i without altering the committer date, All changes made by commits in the current branch but that are not in a patch already accepted upstream with a different commit message or timestamp will be​  Git has two different types of timestamp associated with a commit. Although both may typically hold the same value they are used in subtly different ways. The author (GIT_AUTHOR_DATE) is the user who originally created the work (i.e. a patch), where as the committer (GIT_COMMITTER_DATE) is the user who last applied the work (i.e. applied patch


If you've already screwed up the commit dates (perhaps with a rebase) and want to reset them to their corresponding author dates, you can run:

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

git-rebase Documentation, Would it make sense to perform git rebase while preserving the commit timestamps? I believe a consequence would be that the new branch will  Re: git rebase -i without altering the committer date Am 20.04.2016 um 23:47 schrieb Andreas Schwab: > Shaun Jackman < [hidden email] > writes: > >> I'd like to insert a commit between two commits without changing >> the committer date or author date of that commit or the subsequent >> commits.


A crucial question of Von C helped me understand what is going on: when your rebase, the committer's timestamp changes, but not the author's timestamp, which suddenly all makes sense. So my question was actually not precise enough.

The answer is that rebase actually doesn't change the author's timestamps (you don't need to do anything for that), which suits me perfectly.

git rebase without changing commit timestamps?, A crucial question of Von C helped me understand what is going on: when your rebase, the committer's timestamp changes, but not the author's timestamp,  avant le rebase, enregistrez le timestamp du committer, le timestamp de l'auteur et le message de propagation de toutes les propagations qui seront redirigées vers un fichier. #NOTE: BASE is the commit where your rebase begins git log --pretty='%ct %at %s' BASE..HEAD > hashlog alors, que le rebase réel ait lieu.


By default, git rebase will set the committer's timestamp to the time when the new commit is created, but keep the author's timestamp intact. Most of time, this is the desired behavior, but at some scenarios, we dot not wish to change the commiter's timestamp either. How can we accomplish that? Well, here is the trick I usually do.

First, make sure each of the commits you are about to rebase has a unique commit message and author timestamp (This is where is trick needs improvements, currently it suits my needs though).

Before the rebase, record the committer's timestamp, author's timestamp and commit message of all the commits which will be rebased to a file.

#NOTE: BASE is the commit where your rebase begins
git log --pretty='%ct %at %s' BASE..HEAD > hashlog

Then, let the actual rebase take place.

Finally, we replace the current committer's timestamp with the one recorded in the file if the commit message is the same by using git filter-branch.

 git filter-branch --env-filter '__date=$(__log=$(git log -1 --pretty="%at %s" $GIT_COMMIT); grep -m 1 "$__log" ../../hashlog | cut -d" " -f1); test -n "$__date" && export GIT_COMMITTER_DATE=$__date || cat'

If something goes wrong, just checkout git reflog or all the refs/original/ refs.

Furthormore, you can do the similar thing to the author's timestamp.

For example, if the author's timestamp of some commits are out of order, and without rearrange these commits, we just want the author's timestamp to show in order, then the following commands will help.

git log --pretty='%at %s' COMMIT1..COMMIT2 > hashlog
join -1 1 -2 1 <(cat hashlog | cut -f 1 | sort -nr | awk '{ print NR" "$1 }') <(cat hashlog | awk '{ print NR" "$0 }') | cut -d" " -f2,4- > hashlog_
mv hashlog_ hashlog
git filter-branch --env-filter '__date=$(__log=$(git log -1 --pretty="%s" $GIT_COMMIT); grep -m 1 "$__log" ../../hashlog | cut -d" " -f1); test -n "$__date" && export GIT_AUTHOR_DATE=$__date || cat'

Git Squash Commits and Change Timestamp · GitHub, Now we want to squash these commits into one commit (i.e., the latest commit on 2017/06/23). git rebase -i HEAD~4. Here it's 4 because there are 4 commits. By  Stage the file/s (git add <file>) Commit the change/s (git commit) When you’ve finished the amends you need execute git rebase --continue to proceed with step 5 and complete the process. At the end of the process you’ll have 4 commits in the history rather than 3.


Change the date of a git commit · Code with Hugo, GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)" Rebase to before said commit and stop for amendment: git  If we want to change the commit message of Commit 1, then choose r - reword instead of p - pick. And then we will change the commit timestamp of Commit 1. This can be done as follows: GIT_COMMITTER_DATE="`date`" git commit --amend --date "`date`" This set the commit timestamp as current timestamp.


How can one change the timestamp of an old commit in Git, The commit rebase process stops improve the commit git commit --amend --date=​"Wed Feb 16 14:00 2011 +0100". Following the LC_ALL=C GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)". which will show a graph of your commit log history and may be easier to visualize your commits. Sometimes you will have large enough number of commits that counting can become troublesome. In that case grab the SHA from the last commit that your branch branches from. Squash to 1 commit. git rebase -i HEAD~[NUMBER OF COMMITS] OR. git rebase -i [SHA]


Change the date of a git commit, GIT_COMMITTER_DATE="Mon 20 Aug 2018 20:19:19 BST" git commit --amend --no-edit --date "Mon 20 Aug 2018 20:19:19 BST". Rebase to  Set the date of an arbitrary commit to an arbitrary or current date. Rebase to before said commit and stop for amendment: git rebase <commit-hash>^ -i; Replace pick with e (edit) on the line with that commit (the first one) quit the editor (ESC followed by :wq in VIM) Either: GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)"