GitHub可以显示以补丁形式对一个文件所做的更改的历史记录吗?

ma1*_*w28 88 git version-control github

如果这样做git log --patch -- path/to/file,您将获得文件的历史记录以及每次提交对其进行的所有更改的差异,如下所示:

$ 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
Run Code Online (Sandbox Code Playgroud)

我希望能够使用GitHub的Web界面(而不是命令行)获得相同类型的格式,并且我希望链接在没有代码的情况下发送给其他人.

Tim*_*gan 83

以下URL将以类似于以下格式显示单个文件的所有提交git log -p:

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

...哪里:

  • <username> 是拥有回购的人的用户名
  • <project> 回购品名称
  • <branch> 可以是'主人'或任何其他分支
  • <path/to/file> 希望不言自明

采摘(有点)随机,这是vim-fugitive repo的一个例子.

  • 那是git log path/to/file.我想要git log -p path/to/file. (17认同)
  • 我不知道为什么这会被投票.我想人们不会仔细阅读这个问题.这个答案没有给你一个像'git log --patch - path/to/file``这样的差异列表,这是OP要求的. (4认同)

jhk*_*jhk 48

根据上面的答案和我自己试图找到这个确切的功能,似乎这个问题的正确答案是否定的.

编辑:在你投票之前,也许试着证明我错了.有时正确的答案不是你想听到的.

  • 这个答案既具体又准确,不像其他两个答案甚至不承认问题所在. (18认同)
  • 这是正确的答案.Github无法像git log -p-file一样显示补丁结果和单个文件的日志 (5认同)
  • 其他2个答案都不正确.这个答案为我节省了时间和挫折. (4认同)
  • "这不能解决这个问题." 当然可以,而且节省了我的时间.谢谢jhk. (3认同)

Xub*_*bin 34

使用GitHub接口的直接URL答案(BTW完全正确)的替代方法是:

  • 点击"来源"视图
  • 切换到所需的分支
  • 查找所需的文件,直到找到该文件的实际源视图
  • 点击右上角的"历史记录"

  • 这***也***实际上没有给出原始海报正在寻找的东西.他想要补丁输出,就像他用`git log -p - file`得到的那样.你所展示的只是特定文件的日志,比如`git log - file`,没有diff补丁. (12认同)