assiociatedPullRequests are lost after history rewrite

Using git commit -amend -m "my message" && git push -f to fix a commit message in develop, results in the associatedPullRequest of this commit being lost.

Is there any way to restore this / reassociate them?

I’m aware of the fact that rewriting history is a bad thing. But it happened, and probably will happen again. Because we are generating our changelogs based on the history in develop, and commit messages have a direct impact on how the changelog is being displayed.

query {
  repository(owner: "", name:"") {
    object(expression: "develop") {
      ... on Commit {
        history(first: 5) {
          nodes {
            id
            message

            associatedPullRequests(first: 1) {
              nodes {
                title
              }
            }
          }
        }
      }
    }
  }
}

To my understanding, the associatedPullRequests value is generated from the commit being a part of a specific pull request. Because git only allows creation of new records, not updating of already existing records, when you amend a commit, you are creating a new commit object that looks a lot like the old one but is not the old one. Presumably, you’re amending the commit after the pull request is merged, which means the new commit was never part of the pull request in question.

If you’re using git commit messages and associated pull request information to generate change log entries, I would recommend adding some sort of automation to ensure that commit messages comply with your team’s standards and prevent pull requests being merged unless all commits comply. See commitlint as one example of such tooling.

I hope that helps!

I do understand the cause, and I’m aware that I’m changing the commit hash here.

I was just hoping that there was a mutation or some options to reassociate the new commit, with the “old” pull-request.

That pull-request can be aware that its merge commit is gone. So what I was hoping for is to update the hash of the “pr.merge_commit”. In GitHub that is, not in my git. As that’s obviously not possible.

Unfortunately, there isn’t a way to update that value.