我需要在 master~2
中的 myfile
版本与存在于外部的 myfile
副本之间进行比较存储库本身(比如 D:\folder\myfile
)。
--no-index
下 git-diff
中的措辞是:
git diff --no-index [--options] [--] […]
This form is to compare the given two paths on the filesystem. You can omit the --no-index option when running the command in a working tree controlled by Git and at least one of the paths points outside the working tree
“至少一个”的措辞似乎暗示可以在一个 repo 文件和一个非 repo 文件之间进行比较,但实际上:
$ git diff master~2:myfile D:/folder/myfile error: Could not access: 'master~2:myfile' $ git diff master~2:myfile -- D:/folder/myfile fatal: D:/folder/myfile: 'D:/folder/myfile' is outside repository $ git diff --no-index master~2:myfile -- D:/folder/myfile usage: git diff --no-index <path> <path>
实现这种比较的最简单方法是什么?
最佳答案
在不使用 git-diff
的情况下,我找到了一种间接的方法来实现这一点 - this blog post 中给出的方法,只需使用外部文件作为原始“当前文件”,并确保在执行 git show
之前将 repo 目录作为当前目录。
涉及的步骤是:
- 以通常的方式在 vim 中打开外部非 repo 文件
- 执行
:vsp new
以垂直拆分新的(空白)窗口 :cd
到git仓库的工作目录:read !git show master~2:myfile
读取 myfile 的内容,因为它是 2 次提交前的内容setf yourfiletypehere
用于语法高亮(可选):diffthis
在一个窗口中,然后切换到另一个窗口并再次运行:diffthis
,你就有了 diff
关于git - git 可以在 repo 文件和外部(非 repo )文件之间进行区分吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30650141/