90

If you do git log --patch -- path/to/file, you will get the history of the file along with a diff of all the changes made to it with each commit, like this:

$ git log --patch -- git-rebase.sh

commit 20351bb06bf4d32ef3d1a6849d01636f6593339f
Author: Ramkumar Ramachandra <artagnon@gmail.com>
Date:   Sat Jun 15 18:43:26 2013 +0530

    rebase: use 'git stash store' to simplify logic

    rebase has no reason to know about the implementation of the stash.  In
    the case when applying the autostash results in conflicts, replace the
    relevant code in finish_rebase () to simply call 'git stash store'.

    Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>

diff --git a/git-rebase.sh b/git-rebase.sh
index d0c11a9..17be392 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -153,11 +153,8 @@ finish_rebase () {
                then
                        echo "$(gettext 'Applied autostash.')"
                else
-                       ref_stash=refs/stash &&
-                       >>"$GIT_DIR/logs/$ref_stash" &&
-                       git update-ref -m "autostash" $ref_stash $stash_sha1 ||
-                       die "$(eval_gettext 'Cannot store $stash_sha1')"
-
+                       git stash store -m "autostash" -q $stash_sha1 ||
+                       die "$(eval_gettext "Cannot store \$stash_sha1")"
                        gettext 'Applying autostash resulted in conflicts.
 Your changes are safe in the stash.
 You can run "git stash pop" or "git stash drop" it at any time.

commit 2e6e276decde2a9f04fc29bce734a49d3ba8f484
Author: Ramkumar Ramachandra <artagnon@gmail.com>
Date:   Fri Jun 14 18:47:52 2013 +0530

    rebase: use peel_committish() where appropriate

    The revisions specified on the command-line as <onto> and <upstream>
    arguments could be of the form :/quuxery; so, use peel_committish() to
    resolve them.  The failing tests in t/rebase and t/rebase-interactive
    now pass.

    Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>

diff --git a/git-rebase.sh b/git-rebase.sh
index d0c11a9..6987b9b 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -434,7 +434,7 @@ then
                shift
                ;;
        esac
-       upstream=`git rev-parse --verify "${upstream_name}^0"` ||
+       upstream=$(peel_committish "${upstream_name}") ||
        die "$(eval_gettext "invalid upstream \$upstream_name")"
        upstream_arg="$upstream_name"
 else
@@ -470,7 +470,7 @@ case "$onto_name" in
        fi
        ;;
 *)
-       onto=$(git rev-parse --verify "${onto_name}^0") ||
+       onto=$(peel_committish "$onto_name") ||
        die "$(eval_gettext "Does not point to a valid commit: \$onto_name")"
        ;;
 esac

I want to be able to get the same kind of format using GitHub's web interface (not the command line), and I want a link to send to someone else without the code.

ma11hew28
  • 121,420
  • 116
  • 450
  • 651
  • [Compare View](https://github.com/blog/612-introducing-github-compare-view) gives you something close to what you're looking for, but it's not for an individual file, unfortunately. –  Jul 14 '13 at 00:08
  • 2
    If you make a feature request for it, maybe the GitHub dev team will add it. –  Jul 14 '13 at 00:15

4 Answers4

84

The following URL will show all the commits for a single file in a format similar to git log -p:

http://github.com/<username>/<project>/commits/<branch>/<path/to/file>

...where:

  • <username> is the username of the person that owns the repo
  • <project> is the repo name
  • <branch> can be 'master' or any other branch
  • <path/to/file> is hopefully self-explanatory

Picking at (somewhat) random, here is an example from the vim-fugitive repo.

Tim Henigan
  • 60,452
  • 11
  • 85
  • 78
  • +1. More of those Commits API: http://develop.github.com/p/commits.html (in the GitHub API section http://develop.github.com/) – VonC Jun 01 '10 at 19:22
  • 19
    That's git log path/to/file. I want git log -p path/to/file. – ma11hew28 Jul 05 '10 at 19:35
  • 1
    All that does is show the latest update, not a history of updates. – Gerry Sep 02 '14 at 18:48
  • Looks exactly correct to me, not sure why it's not checkmarked. I will also note that it's simple to construct the path, just go to the file itself and replace _blob_ with _commits_ in the URL. – John C Apr 16 '15 at 13:31
  • 4
    I don't know why this is getting up voted. I guess people aren't reading the question carefully. This answer does not give you a list of diffs like ``git log --patch -- path/to/file`` which is what the OP asked for. – jcoffland Mar 31 '16 at 17:37
  • 1
    @jcoffland it is being upvoted because most people like me find this helpful and this is exactly what we are looking for, disregarding the op's question though. – mr5 Dec 10 '16 at 15:44
  • While not the answer, this was the next best thing as far as I'm considered, as mr5 mentions. – kabanus Aug 18 '21 at 12:52
50

Based on the answers above and my own attempts to find this exact feature, it appears the correct answer to this question is no.

miken32
  • 42,008
  • 16
  • 111
  • 154
jhk
  • 670
  • 5
  • 9
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – indubitablee Nov 03 '15 at 15:18
  • 18
    This answer is both specific and accurate, unlike the other two responses which fail to even acknowledge what the question was asking. – jhk Nov 04 '15 at 16:36
  • 5
    This is the correct answer. Github does not have a way to show patch results together with the logs for a single file the way git log -p -- file does – nohat Nov 10 '15 at 02:00
  • 4
    the other 2 answers are incorrect. this answer saved me time and frustration. – Schien Apr 21 '16 at 03:30
  • 3
    "This does not provide an answer to the question." Sure does, and one that saved me time. Thanks jhk. – ChrisJJ Jan 08 '17 at 01:27
33

An alternative to the direct URL answer (which BTW is perfectly correct) using GitHub's interface is to:

  • Click on 'Source' view
  • Switch to a desired branch
  • Look for the file you want until you get to the actual source view for the file
  • Click 'history' on the top right corner
Zubin
  • 1,015
  • 1
  • 9
  • 15
  • 13
    This ***also*** does not actually give what the original poster is looking for. He wants patch output, the same as what he would get with `git log -p -- file`. What you have shown is just the log for a particular file, like `git log -- file`, without the diff patches. –  Jul 14 '13 at 00:06
-4

If you're on Linux, Then install TIG as:

sudo apt-get install tig

and then,

tig path/to/file/

It'll show you all the commits and their respective changes

Talat Parwez

Talat Parwez
  • 129
  • 4