Github/compare: How to diff two different files (different file names, both in HEAD)?

后端 未结 5 1606
灰色年华
灰色年华 2021-02-06 23:50

Can I use the github /compare to display the difference between two different source files in HEAD?

Here is how I do it on the command line with git d

相关标签:
5条回答
  • 2021-02-07 00:03

    I have been using this third party online diff tool for a long time, if you like, you can use it as well. https://www.diffchecker.com. But it seems you should manually paste the two files onto it.

    0 讨论(0)
  • 2021-02-07 00:06

    I sometimes use Diff Checker tool on the diffchecker website. It is an online diff tool to compare text differences between two text files.

    Link: https://www.diffchecker.com/diff

    0 讨论(0)
  • 2021-02-07 00:09

    The Situation

    On my DevOps team, it is very common to need to create new infrastructure resources (via Infrastructure As Code) which closely resembles existing infrastructure but with just a few changes. When a GitHub "Pull Request is received, the code reviewer is shown thousands of lines of code to Review and Approve. Even if they knew which small portion of the code should be changed, they should feel comfortable assuming "all that other green/new code must have be copied correctly from the correct spot.

    I KNOW HOW TO DO THIS VIA THE CLI! But, because we have a workflow that centers around GitHub Enterprise (and private repos) my team doesn't use the CLI for this or much of anything.

    The Stopgap Solution

    Since GitHub only accepts points in history for comparisons and not paths I have to get clever.

    Assuming FileA is the original and FileB is the modified file at a new path

    • Create a temporary branch (using a naming convention like "diff-TICKET-1234")
    • Copy FileA on top of FileB
    • Commit it
    • Push it out to github
    • In the last commit message in the branch that is getting a PR (in this case "TICKET-1234"), add a comment:
      • See: https://github.com/org_name/repo_name/compare/diff-TICKET-1234..TICKET-1234
    0 讨论(0)
  • 2021-02-07 00:16

    Line Diff will display a github like diff between two code snippets, however you won't be able to specify the source files as current HEAD on github - I just think it's an edge case and no one has yet thought of making it a "feature" in one of these online tools.

    0 讨论(0)
  • 2021-02-07 00:21

    This is a little cheat-y, and you should look into the "premium" options: Hitting a DiffNow endpoint will give you a JSONp callback with the name of a temporary HTML file containing a diff.

    https://www.diffnow.com/EdpProcess.aspx?action=compareUrls&url1=https%3a//raw.githubusercontent.com/RossBencina/Fractorp/master/docs/implementing-tutorial/01-boxed-function-pointers.cpp&url2=https%3a//raw.githubusercontent.com/RossBencina/Fractorp/master/docs/implementing-tutorial/02-raw-actors.cpp
    
    0 讨论(0)
提交回复
热议问题