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

22,125

Solution 1

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

Solution 2

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.

Solution 3

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
Share:
22,125
Ross Bencina
Author by

Ross Bencina

I'm the creator of AudioMulch, software for live music performance. My open source projects: PortAudio - A cross-platform audio I/O library that I co-founded with Phil Burk. reacTIVision - Marker tracking library. I invented the "amoeba" fiducial markers. oscpack - A popular C++ Open Sound Control (OSC) library oscgroups - A peer-to-peer multicast (peercast?) infrastructure for OSC I'm available for freelance work. My skills include: full lifecycle software design and implementation, troubleshooting, C/C++, real-time audio, network programming, user interfaces, Qt, Python, Lua. No project is too strange or too interesting. Platform experience Windows: lots, Mac OS X: a fair bit, Linux: some, iOS: a bit, Android: a tad.

Updated on March 10, 2020

Comments

  • Ross Bencina
    Ross Bencina about 4 years

    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 diff:

    git diff HEAD:docs/tutorial/01-boxed-function-pointers.cpp HEAD:docs/tutorial/02-raw-actors.cpp

    My best guess at the github syntax is the following. But it doesn't work:

    https://github.com/RossBencina/Fractorp/compare/HEAD:docs/tutorial/01-boxed-function-pointers.cpp...HEAD:docs/tutorial/02-raw-actors.cpp

    I specifically want an on-line pretty-printed HTML render of the diff.

    If this can't be done with github, can anyone recommend a third-party website that will render diffs of two arbitrary files hosted on github?

    Edit #1:

    Thanks to the answers who recommended https://www.diffchecker.com. However, I need to be able to specify the source files as current HEAD on github. Any third-party tool would need to automatically pull the latest source files from github repo URLs. I notice that http://www.mergely.com can import source from URLs. However I am looking for a live view that always uses the latest HEAD.

    Thank you.