When I write code I break it into small logical changes that are easy and quick to review.
To do so, I use git rebase -i
(interactive) to squash, drop and change order of commits.
I've noticed this sometimes leads to a different order of commits on a GitHub pull request (though the order is retained on the remote branch).
For example,
might show up in the PR as:
I've searched the internet and only managed to find this GitHub help page: Why are my commits in the wrong order? Their answer:
If you rewrite your commit history via git rebase or a force push, you may notice that your commit sequence is out of order when opening a pull request.
GitHub emphasizes Pull Requests as a space for discussion. All aspects of it--comments, references, and commits--are represented in a chronological order. Rewriting your Git commit history while performing rebases alters the space-time continuum, which means that commits may not be represented the way you expect them to in the GitHub interface.
If you always want to see commits in order, we recommend not using
git rebase
. However, rest assured that nothing is broken when you see things outside of a chronological order!
Is there a way to work around this?
With Interactive Rebase, Git offers a very powerful tool to edit / rewrite / reorder / etc. existing commits. Please note that Interactive Rebase is only available for the currently checked out branch.
(drop) — If you remove a commit from the interactive rebase file, or if you comment it out, the commit will simply disappear as if it had never been checked in. Note that this can cause merge conflicts if any of the later commits in the branch depended on those changes.
To update by rebasing, click the drop down menu next to the Update Branch button, click Update with rebase, and then click Rebase branch. Previously, Update branch performed a traditional merge that always resulted in a merge commit in your pull request branch.
I've managed to work around this by:
git rebase -i <hash of that commit>
pick
with reword
git push -f
Before that, I tried changing only the first commit message, which also changes all the following hashes, but that didn't fix it.
I had to do it for every following commit too for it to work.
To automate what Eliad suggested I use a script from Piotr:
git rebase "$(git merge-base HEAD master)" --ignore-date -x 'git commit --amend -C HEAD --date="$(date -R)" && sleep 1.05'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With