How do you recreate the GitHub pull request diff on the commandline?

后端 未结 6 947
终归单人心
终归单人心 2021-02-18 21:20

While working on a branch that I\'ve opened a pull request on, I would like to see the exact same diff that GitHub displays on the commandline. What is the particular git diff c

6条回答
  •  南方客
    南方客 (楼主)
    2021-02-18 22:06

    Assuming that you want to check against the base branch called master:

    git diff $(git merge-base --fork-point master)
    

    This will give all the changes since the branch was made, including yet uncommitted changes!

    This command gives the same results as the one in @pic's answer, but it's a bit simpler as it doesn't require knowing the feature-branch.

    If you want only the committed changes, similar to gh pr diff command as in @VonC's answer, the following command will give the same results:

    git diff $(git merge-base --fork-point master) HEAD
    

    The git diff way approach could be more useful in some situations, since you have all the other git diff features available. For example, if you don't want the diff, but instead want to know which files were modified, you can just pass the --name-only:

    git diff --name-only $(git merge-base --fork-point master)
    

    which you can't do with gh.

提交回复
热议问题