列出给定提交 ID 之前的提交

List commits BEFORE the given Commit ID

我的 repo 顶层层次结构如下所示:

/dir1
/dir2
/dir3

我在 HEAD 并且 git log --oneline --first-parent -5 -- dir1/ 给出了如下内容:

abcb COMM-25 Fix latest
ba0f COMM-17 Some stuff
cda8 New files
db7c COMM-9 Feature merge
e20a Init smth

网络上有很多很酷的东西,比如 git log --oneline --first-parent db7c.. -- dir1/ 可以得到

abcb COMM-25 Fix latest
ba0f COMM-17 Some stuff
cda8 New files

甚至git log --oneline --first-parent db7c..ba0f -- dir1/两端限制

ba0f COMM-17 Some stuff
cda8 New files

但是,地狱,我找不到任何可以帮助输出所有提交到特定提交 ID 的东西。 我需要 git log --oneline --first-parent ..cda8 -- dir1/ 之类的东西才能得到

cda8 New files
db7c COMM-9 Feature merge
e20a Init smth
<...>

只有 cda8 哈希。 上面的最新命令当然是伪代码,在现实生活中不提供任何输出(不幸的是:))。

那么,如何在不更改 HEAD 的情况下列出特定目录中和给定提交 ID(含)之前的所有提交?

我想我可以接受修改 dir1 的内容(仅 dir1,不涉及 dir2 和 dir3!),但是 git checkout cda8 dir1/git reset cda8 dir1/ 对后续 git log <...> -- dir1/ 输出.

请帮助,git 大师们!

我认为您在这里 很努力地尝试过,这就是阻止您看到隐藏在众目睽睽之下的解决方案的原因。

当给定 refspec 时,您要求的 标准日志行为 。它将记录 所有提交历史记录 从那一点可以到达* :

git log --oneline --first-parent cda8 -- dir1/

(请注意,我已经完成了您的最后一次尝试,省略了“..)应该输出:

cda8 New files
db7c COMM-9 Feature merge
e20a Init smth
...
<follows ALL the rest of commits history (but only those which have modified dir1/)>

* "reachable" in git 应该理解为 "reachable through a recursive exploration of a given commit's parents"