Force push a branch without losing review comments

I need to force push a branch to github. The pull request has about 50 comments.

My understanding is that I should still be able to see the comments after force pushing. It will say ‘so and so commented on an outdated diff’.

Is this correct?? I just want to make sure I don’t lose the comments.

Thanks

Are the comments attached to the pull request, or particular lines of code or commits?

If they’re on the PR itself they should persist.

If they’re on a particular line of code or commit, I think they persist if the given line of code/commit hash is unchanged. Note that the commit hash can change if prior commits were altered, even if the commented commit itself did not change.

On a PR when someone comments on code/commits, the comment is automatically displayed in the PR comments as well - which is what leads to this confusion. In general, I encourage people to comment on the PR directly and link to the lines of code/commits as needed.

You can at least look through the comments before force pushing and if you identify anything that will be lost, you can quote the text in a new comment on the PR itself.

NB: this info is based on my personal experience which may be outdated.

2 Likes

Yes that will happen, like mark said. If the comments are important, I recommend pushing to a different branch on the remote repository.
You can do this easily with git push origin 'name-of-new-branch'. You will need to create a new PR for that branch, in which you can refer to the original one.

1 Like

“refer to and close the original”

:+1: this is less work than recreating comments.

1 Like

Yes, that’s also my experience, we had this discussion in a pull request a year ago, I don’t find it now :slightly_smiling:
The essence was that comments are only kept with the PR if the commenter used the Files changed view. If a commented commit gets orphaned, the comments are still with this commit, but not visible in the PR history.

Unfortunately, commenting in the diff view is not very handy if the PR contains formatting commits changing large numbers of files…