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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2952507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:29:46  来源:igfitidea点击:

Can GitHub show the history of changes made to one file in patch form?

gitversion-controlgithub

提问by ma11hew28

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 -- path/to/file,您将获得文件的历史记录以及每次提交时对其所做的所有更改的差异,如下所示:

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

commit 20351bb06bf4d32ef3d1a6849d01636f6593339f
Author: Ramkumar Ramachandra <[email protected]>
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 <[email protected]>
    Signed-off-by: Junio C Hamano <[email protected]>

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 <[email protected]>
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 <[email protected]>
    Signed-off-by: Junio C Hamano <[email protected]>

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.

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

回答by Tim Henigan

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

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

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

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
  • <username>是拥有 repo 的人的用户名
  • <project>是回购名称
  • <branch>可以是“master”或任何其他分支
  • <path/to/file>希望是不言自明的

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

选择(有点)随机,这是来自vim-fugitive repo 的一个例子。

回答by jhk

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

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

Edit: before you down vote, maybe try and prove me wrong. Sometimes the correct answer isn't what you want to hear.

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

回答by Xubin

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

使用 GitHub 界面的直接 URL 答案(顺便说一句是完全正确的)的替代方法是:

  • 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
  • 单击“源”视图
  • 切换到想要的分支
  • 查找所需的文件,直到进入文件的实际源代码视图
  • 点击右上角的“历史”

回答by Talat Parwez

If you're on Linux, Then install TIGas:

如果您使用的是 Linux,则将TIG安装为:

sudo apt-get install tig

sudo apt-get install tig

and then,

进而,

tig path/to/file/

tig 路径/到/文件/

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

它将向您显示所有提交及其各自的更改

Talat Parwez

塔拉特·帕韦兹