Home > front end >  Why would a commit be listed in two different pull requests?
Why would a commit be listed in two different pull requests?

Time:01-12

I have been doing some mining work, I noticed that sometimes different pull requests may have the same commit (based on the sha, I could tell they are same). I am just wondering what would be the reason behind it?

Example:

  • Pull request 1 has two commits: sha1, sha2
  • Pull request 2 has three commits: sha3, sha4, sha1

Why does sha1 exist in both pull requests?

CodePudding user response:

It appears that the repository is set up like this, with five commits and four branches:

                Branch diagram

Every pull request has a source branch and a target branch:

  • The first pull request is from branch Y to branch X, which means commits sha1 and sha2.
  • The second pull request is from branch B to branch A, which means commits sha3, sha4, and sha1.

It's not normal to have pull requests overlap like this. One or both pull requests ought to be edited to disentangle them from each other. Nevertheless, this appears to be the situation.

CodePudding user response:

Why it happened is because the branch of one PR was started from incomplete (perhaps?) work from the other PR. It's not like an end-of-the-world situation. Then, if you push both branches for 2 different PRs, that work would be present on both branches/PRs. This is something that you probably would like to avoid. The way to untangle them is normally through rebasing so that you clear one branch from the common work of the other branch. Not technically imoossible, just requires certain finesse:

git checkout feature1
git rebase --onto main feature2 feature1

Which will place the revisions of feature1 on top of main getting rid of the common revisions between feature1 and feature2.

As an additional insight, it could also happen if the base branch was rewritten (not recommended to be done but possible, nevertheless) and the other branches that had been started from the old history. Then both branches/PRs would keep those same revisions of the old history in common.

  •  Tags:  
  • Related