Editing Commit Timestamps in Git

chris48s

chris48s

Posted on May 3, 2021

Editing Commit Timestamps in Git

I always forget that GitHub shows commits in a pull request in timestamp order rather than tree/history order until just after I've just pushed a monster rebase and everything's in the wrong order. To force GitHub to show the commits in the correct order, we need to edit the commit timestamps to match the history order. To do this:

git rebase -i HEAD~N
Enter fullscreen mode Exit fullscreen mode

Mark the commits that need re-ordering as edit

edit f3b9e40 Reticulate Splines
edit 68f39b8 Adjust Bell Curves
edit d605e5a Dice Models
Enter fullscreen mode Exit fullscreen mode

At each stage of the rebase:

git commit --amend --date=now --no-edit
git rebase --continue
Enter fullscreen mode Exit fullscreen mode

Now the timestamp ordering will match the history. When you force-push, GitHub will order the commits correctly in your pull request.

💖 💪 🙅 🚩
chris48s
chris48s

Posted on May 3, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related