DEV Community

loading...

Editing Commit Timestamps in Git

chris48s
Originally published at chris48s.github.io ・1 min read

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.

Discussion (0)