Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 5

GitHub pull requests showing invalid diff for already merged branch

We’re seeing an issue with how pull requests are performed by GitHub. When we model a pull request after previously merging a change from one branch into another, it’s previewing the same “diff” as before, even though we can show the previous change was indeed already made to the branch. GitHub seems to get into this infinite loop of trying to reapply the same change as already merged each time we model the pull request, regardless of how many times we try to merge it. And when each such pull request is actually merged, git in fact does the right thing: nothing! The supposed merge commit will show “0 Changed files with 0 additions and 0 deletions”. Why is GitHub lying to us about what the differences are between our 2 branches?
4 Replies
Commander Lvl 3
Message 2 of 5

Re: GitHub pull requests showing invalid diff for already merged branch

That seems like a bug. You might want to report that here: https://github.com/contact.


- Mark
Copilot Lvl 2
Message 3 of 5

Re: GitHub pull requests showing invalid diff for already merged branch

Yes, I agree. GitHub seems to think this is a design feature, however. Their response when I posted via that form, below. From my persepctive though it's still giving an incorrect answer. It’s showing a difference when there actually isn’t one, and then offering to do a merge assuming that difference, which ultimately results in a no-op because there actually isn't one. Definitely feels like a bug to me too!

 

From GitHub: 

"When you merge commits from a Pull Request into a branch, the commit SHA changes from what the original commit SHA's were.

This means when you compare the same two branches again, the diff will show those commits again because those specific commit SHA's don't exist on the branch you're merging into.

This is a result of the type of diff we use on GitHub. We use git's three dot diff, which is the difference between the latest commit on the HEAD branch and the last common ancestor commit with the base branch.

This workflow is designed for a topic branch model. The presumption with the topic branch flow is that a branch is created to merge in a specific feature. Once the branch has been merged it would be deleted and further development would be made on a new branch.

A lot of teams use a master > dev branch model though and for this, once a Pull Request is merged, the master branch would be merged back onto dev using the command line:

git checkout devgit rebase master Rebasing the master back onto dev updates dev with the latest commits from master and should give you a clean diff again.!"

Ground Controller Lvl 1
Message 4 of 5

Re: GitHub pull requests showing invalid diff for already merged branch

great explaination for the github diff mechanism!

Ground Controller Lvl 1
Message 5 of 5

Re: GitHub pull requests showing invalid diff for already merged branch

Just checked this locally by:

 

1. creating a repo with 1 file and committing it to commit "A", in master

2. Checkout to a new branch called "mybranch" and do a `git reset head~1`

3. Make a new commit to commit "B" with the exact same content as "A"

4. `git diff master` (on mybranch) gives no results, as expected.