如何区分 HEAD 和更改文件的第 n 个最后修订版?

问题描述 投票:0回答:1

如果我想查看两次提交之间单个文件的差异,我可以运行类似的命令

git diff HEAD..HEAD~3 -- file

不幸的是,如果该特定文件在这些提交之间没有更改,则该命令毫无用处。如果我不想使用

gitk
,我必须使用

查找提交
git log -- pathto/file

然后手动将这些提交传递给

git diff

是否有某种技巧结合了历史简化,可以使用某种简化的语法(如

HEAD~3
)来引用更改该特定文件的第三次先前提交,而不仅仅是先前第三次提交?

git git-diff
1个回答
1
投票

用于区分 HEAD 和路径的最后 n 个修订版的别名

我想出了一个名为

ndiff
的别名。跑步

git ndiff <number> <path>

显示更改

<n>
(可能是文件或目录)的最后一个修订版本(按拓扑顺序)之间的差异。要定义此别名,请使脚本可执行,将其放在搜索路径中,然后运行
<path>

示例

这是对我的一个存储库中的别名的测试。与您的存储库中一样,最后三个提交没有更改

git config --global alias.ndiff '! git-ndiff'

文件:

README

但是,使用我的 
$ git log HEAD~3..HEAD -- README $

别名,我可以与更改的第三个最后提交进行比较

ndiff
,如下所示:
README

快乐的日子!

脚本

(该脚本可在 GitHub 上的

Jubobs/git-aliases

获取。) $ git ndiff 3 README diff --git a/README b/README index d482a72..5b6d0b5 100644 --- a/README +++ b/README @@ -10,4 +10,5 @@ LaTeX & friends. Three predefined styles, one of which closely mimicks that of the Matlab editor, are available and can be invoked by listings macros and environments in conjunction with (most) options provided by the listings package. The appearance of your Matlab listings can be further tweaked via a -key-value interface extending that of listings’. +key-value interface extending that of listings'. Partial support for Octave +syntax is provided. $

© www.soinside.com 2019 - 2024. All rights reserved.