Jump to the navigation menu

Rebase and reorder

Sometimes when tidying my commits or updating a local branch with remote changes, the order of commits changes - making them out of order in when running git log.

I want the commits in the log to be in the correct sequential order.

If not, it would be confusing if I review the commits in the future.

This is easy to fix when running git rebase -i to perform an interactive rebase on the commits.

The commit has a -x or --exec option that will perform a given command on each commit.

The commit date can be reset using git reset --amend, and combining these commands will amend the date of each commit.

Running git rebase --interactive --exec "git commit --amend --no-edit --date now" will amend and update each commit, keeping the commit message the same, but changing the commit date to the current time - leaving the Git log in the correct order.

- Oliver

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an certified Drupal Triple Expert with 18 years of experience, a Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.