0

On GitHub, there's a way to do a "diff" between 2 commits. https://help.github.com/en/github/committing-changes-to-your-project/comparing-commits

In a nutshell, it looks like this: https://github.com/github/linguist/compare/c3a414e..faf7c6f

If I wanted to compare between a certain commit in history vs. the current head of the branch, how would I do this? I don't want to always have to always look up the 7-character SHA code of the latest commit.

I've tried https://github.com/github/linguist/compare/c3a414e..head but that doesn't work.

Cog
  • 1,545
  • 2
  • 15
  • 27
  • Does this answer your question? [How to compare two different commits on the same branch in github?](https://stackoverflow.com/questions/49837769/how-to-compare-two-different-commits-on-the-same-branch-in-github) – Pankaj Singhal Oct 06 '20 at 16:57

1 Answers1

2

Give it the name of the branch.

https://github.com/github/linguist/compare/c3a414e..master

You can do it manually, or use the base and compare drop downs.

In general, commit IDs, branch names, and tags are interchangeable. They are all "revisions" which specify a commit. See gitrevisions for the ways you can identify commits. For example, you can compare against where master was two years ago.

https://github.com/github/linguist/compare/c3a414e..master@{2 years ago}

head did not work because the names are case-sensitive. It is HEAD. HEAD is a special reference. On your local repository HEAD is the currently checked out commit. On Github it will be the tip of the default branch on Github, probably master. If you want master you're better off asking for master.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • The `@{2 years ago}` syntax only works locally and requires that your reflog contain two years' worth of updates, which is probably somewhat rare since the default expiry is 90 days. :-) (It depends of course on whether you've changed these defaults *and* whether `git gc` has run.) – torek Mar 13 '20 at 23:09
  • 1
    @torek [Did you try it?](https://github.com/github/linguist/compare/c3a414e..master@%7B2%20years%20ago%7D). I was a bit surprised. – Schwern Mar 13 '20 at 23:18
  • Huh, interesting. This must be a GitHub feature. They have reflogs turned off (as far as I know) so they must be interpreting it some other way (probably looking at commit timestamps). – torek Mar 13 '20 at 23:28
  • @torek I assume they have reflogs and aren't pruning them. They're cheap. – Schwern Mar 13 '20 at 23:33
  • That's possible, but when you force-push, unreachable commits (which would be held by reflogs) do eventually vanish. So if they're keeping them, they've configured the expire-unreachable setting short-ish and the regular (reachable) setting to never (or years). – torek Mar 14 '20 at 00:04