git rebase -i #rewrite all commits in this branch git rebase -i HEAD~3 # rewrite last 3 commits in this branch
This will open the default text editor with the specified commits.
NOTE that the order differs from the log. This order is chronological from top to bottom.
pick f7f3f6d changed my name a bit pick 310154e updated README formatting and added blame pick a5f4a0d added cat-file # Rebase 710f0f8..a5f4a0d onto 710f0f8 # # Commands: # p, pick = use commit # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #
Then you can replace all the first word / action at each line, which will make what you want.
To modify the timestamp of a commit while rebasing:
export newDate="`date`" GIT_COMMITTER_DATE="$newDate" git commit --amend --no-edit --date "$newDate" && git rebase --continue
Or as a single command:
GIT_COMMITTER_DATE=(date) git commit --amend --no-edit --date "$GIT_COMMITTER_DATE"