user2167582
user2167582

Reputation: 6368

how to get a preview of what Github's pull request diff will look like

How to do diff between branches to get what the Merge diff will look like

consider this graph

*   master
|\
| * b1
|\ 
| * b2

if im on b2, and the person on b1 beat me and merged into master,

if i do

project>b2 $ git diff origin/master

the diff would include b1, which would not be included in the PR, how do I reproduce this in command line.

Upvotes: 2

Views: 3401

Answers (3)

VonC
VonC

Reputation: 1324278

With Git 2.38+ (Q3 2022), you can use quickly check if there will be conflicts between your feature branch and the PR target branch, using git merge-tree --write-tree:

git merge-tree --write-tree --no-messages --name-only branch1 branch2

With a GUI like GitHub Desktop (for remote GitHub repositories), you actually can, since March 2023:

GitHub Desktop 3.2: Preview your pull request

In GitHub Desktop 3.1, we introduced viewing the diff of changes across multiple commits.
This allows you to be certain there are no unintended changes in the group of commits you are about to push.

Taking that feature to the next level, GitHub Desktop 3.2 allows you to “Preview your Pull Request”– see a diff of all the changes being introduced by your feature branch into your repository’s default branch.

GitHub Desktop helps you feel confident in your Git workflows, and now we want to help you feel confident in your GitHub workflows as well.

Preview your pull request

If you find yourself apprehensive to push your changes up to GitHub.com and open a pull request, you will like the confidence boost reviewing your pull request locally will give you.
Have you ever submitted a pull request only to find you’ve accidentally left in a debugger statement, requiring you to return back to your local environment, remove the debugger, commit, and push up the change? This can be annoying, time consuming, and maybe even a little embarrassing.

Now with the “Preview Pull Request” feature, you can see the diff of all the changes brought in from all the commits on your feature branch before opening your pull request. It lets you do that double-checking before leaving your local development environment.

The pull request preview open showing a file change with a debugger in it.

Upvotes: 0

Jellicle
Jellicle

Reputation: 30216

I believe that git merge-tree will do it. It doesn't perform a merge but instead outputs a diff which represents the merge.

It takes three arguments: git merge-tree <base-tree> <branch1> <branch2>

I find it easier to read when piping its output into colordiff and then a pager. (I use less with -r to handle the colors.)

git merge-tree $(git merge-base HEAD b2) HEAD b2 | colordiff | less -r

Upvotes: 1

Schwern
Schwern

Reputation: 164809

You can update origin/master with git fetch origin. This will update your remote branches without changing anything else.

After that, you can rebase your b2 work onto origin/master with git rebase origin/master. Now b2 will be based on the latest work including b1. Then git diff origin/master will reflect the addition of b1.

Then you can update the PR with git push --force.

Upvotes: 1

Related Questions