73

I've found this post about using the command line, but is it possible to view the file change history of a single file in a repository on github.com?

An in-browser solution would help me to better illustrate changes to team members while in meetings.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
propstm
  • 3,461
  • 5
  • 28
  • 41

9 Answers9

43

You can view the change history of a file by clicking on the history button, or by adding commits to the URL of the file. Here is what it looks like for a file at the Homebrew repository on GitHub:

https://github.com/mxcl/homebrew/commits/master/SUPPORTERS.md

To get a line-by-line history, simply add the SHA-1 string of the commit for which you want to see the diff to the URL after the word commit, and then anchor it with the filename you are interested in. For the same file above:

https://github.com/mxcl/homebrew/commit/288f001e924d5365b79c279e4478f372a04011ae#SUPPORTERS.md

To see all commits for a single branch use a URL like this

https://github.com/mxcl/homebrew/commits/master

To see all commits for all branches use a URL like this

https://github.com/mxcl/homebrew/commits

There is no button or link in the web UI for these URLs, but you can bookmark them easily.

John Henckel
  • 10,274
  • 3
  • 79
  • 79
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • 6
    I'm probably just blind, but where's this "history" button? – jozxyqk Oct 02 '18 at 01:47
  • 1
    I think this answer is outdated. I've tried the second link example and the adding anchor `#filename` is totally useless now, Github would show all files' differ no matter whether you adding a `#filename` or not. – Rick Dec 03 '18 at 09:39
  • Are you talking about the [GitHub Desktop application](https://help.github.com/en/desktop/contributing-to-projects/viewing-the-branch-history)? In any case, perhaps update your answer? – Peter Mortensen Apr 14 '20 at 18:00
  • 4
    @jozxyqk , "history" is not a button, it's clickable text. Today (2020-10-30), I found it on the right-edge of the screen about 4-inches down from the address bar, with icon of a clock rotating backwards next to it. – Babar-Baig Oct 30 '20 at 04:45
  • If anybody misses the `History` button, they may want to try a Tampermonkey script that adds GitLab's-like `History` button on GitHub pages: https://gist.github.com/foka/881a73313348927d547420101259abda – foka Jan 14 '22 at 12:25
18

As @BurhanKhalid say, but here explaining as a "GitHub fast guide", with URL syntax:

  1. Browse your project at https://github.com/<USER>/<PROJECT> ...
  2. ... then you have a URL ending with the file path: https://github.com/<USER>/<PROJECT>/blob/master/<PATH>
  3. Now you have all, is only to change "blob/master" to "commits/master": https://github.com/<USER>/<PROJECT>/commits/master/<PATH>

PS: to remember "commits/master" click at the project's home in the "Commit" link.

Ops: there are a similar answer here, @TimHenigan expressed with http://github.com/<username>/<project>/commits/<branch>/<path/to/file>


Question to GitHub developers team

Why do you not offer a direct link for this kind of browsing? We need it, like Wikipedia readers need "history" link!


Ops, GitHub's team is listening to us?

Now (June 2014) when you browse through the folders, an icon appears, see "browse commits" above right. When you click, the tree/master URL turns commits/master.

Still missing to have the same for files, as showed here, but was an evolution.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Peter Krauss
  • 13,174
  • 24
  • 167
  • 304
15

I think git-history is an alternative and good method for quickly browsing the history of files in any Git repository.

You don't need to download anything. You only need to replace the domain in the URL.

Steps to do:

  1. Go to a file in GitHub (or GitLab, or Bitbucket)
  2. Replace github.com with github.githistory.xyz

There are Chrome and Firefox extensions to add an Open in Git History button on GitHub, GitLab and Bitbucket so that you don't need to memorize step 2.

For more information, you can go to its GitHub page.

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
  • 3
    This should really be at the top, since OP was looking for a GUI tool (as was I), and this has the added benefit of not needing to click into each commit, and then take additional steps to diff against the previous change – Adam Smooch Jul 27 '22 at 14:51
10

The GitHub capabilities for history exploration for a file just got a bit better in Apr. 2021 with:

"View file at a specific point in the commit history"

When viewing the commit history of a single file, users can now click to view that file at the selected point in history.

https://i1.wp.com/user-images.githubusercontent.com/16675781/116747128-c01edc00-a9fd-11eb-9009-008305786885.gif?ssl=1 -- view history

From there, type "b" for the blame view of that file in that commit, and explore its changes:

With the blame view, you can view the line-by-line revision history for an entire file, or view the revision history of a single line within a file by clicking before.

Each time you click before, you'll see the previous revision information for that line, including who committed the change and when.

Git blame view

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    That "view at this point in history" button was what I was looking for to get line-by-line differences for a single file. Thank you. – Wassadamo Dec 22 '22 at 19:21
2

As of , if you want to view all the change records in a easy way on GitHub, NO, I did not find an easy way to do that in browser.

How you view one commit change history on GitHub:

  1. You visit any file, let's say hello.cpp on GitHub, click the "history" button, then you can see the commits that change this file.
  2. Then by clicking each commit's "sha" button, you see the whole commit.
  3. Then you find hello.cpp, click "view file" button. And finally you only see the difference of this commit - last commit.

So if you want to look through all the history changes, you have to repeat the process above for so many times.. and open so many tabs...


You can use gitk [filename](GUI) or git log -p filename(Command line) to view all history changes of a single file easily.

Source: View the change history of a file using Git versioning

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rick
  • 7,007
  • 2
  • 49
  • 79
1

Check out https://github.com/pomber/git-history a very handy UI tool (and plugin) visualization of file changes through time.

enter image description here

Aziz Alto
  • 19,057
  • 5
  • 77
  • 60
1

Both Github Desktop and github.com have surprisingly limited capabilities for history diffs.

Option 1 (preferred): migrate to Atlassian Bitbucket; much better experience overall; integration with JIRA, etc.

Option 2: if you are on Windows - try Tortoise GIT desktop client; has Show Log feature which I find very helpful for side-by-side diffs.

Paul Shiryaev
  • 161
  • 1
  • 9
-1

You can read this official article firstly, and then I will show you a demo!

https://developer.github.com/v3/repos/commits/

Here is the demo, using the fetch API:

PS: client_id & client_secret you should using yourself!

let username = `xgqfrms-GitHub`;
     repo = `Node-CLI-Tools`;

fetch(`https://api.github.com/repos/${username}/${repo}/commits`,{
    data: {
        client_id: '08ecc2f68d922f188xxx',
        client_secret: '5846d428b5340812b76c9637eceaee979340bxxx'
    }
})
.then((response) => response.json())
.then((json)=> {
    console.log(`json = ${json}`);
    return repos = json;
})
.then((repos)=>{
    console.log(`repos = ${repos}`);
    console.log(`repos = ${repos.length}`);
    for (let i = 0; i < repos.length; i++) {
        console.log(`repos${i}  = ${repos[i].commit.message}`);
    }
});
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
xgqfrms
  • 10,077
  • 1
  • 69
  • 68
-2

Checkout out Little Differ in the Google Chrome webstore. It's a Chrome extension that shows a sidebar displaying the commit history of a repository or a file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
gtria
  • 72
  • 4