我在 CI 盒子上运行测试。为了加快速度,我只是做了一个浅克隆:
git clone --depth 1 [email protected]:JoshCheek/some_repo.git
假设所有测试都通过,我想触发管道中的下一步。触发的内容取决于上次更改的文件d就业(参考d123456
)和c我刚刚测试的当前参考(参考c123456
)。如果我做了一个普通的克隆,我可以发现这样的结果:
git diff --name-only d123456 c123456
但我的克隆很浅,所以它不知道这些提交。我看到我可以使用git fetch --depth=n
以获得更多的历史,但我只知道 SHA,而不知道 SHA 的深度。以下是可能可以回答这个问题的一组方法:
# hypothetical remote diff
git diff --name-only origin/d123456 origin/c123456
# hypothetical ref based fetch
git fetch --shallow-through d123456
git diff --name-only d123456 c123456
# hypothetical way to find the depth I need
depth=`git remote depth-to d123456`
git fetch --depth "$depth"
git diff --name-only d123456 c123456
否则看来我可能必须编写一个循环并继续调用--deepen
直到我的历史记录包含该提交。这看起来很痛苦(意味着编写/维护很烦人)并且昂贵(意味着缓慢,请记住浅层克隆的目的是减少这种成本)。
否则看来我可能必须编写一个循环并继续调用--deepen
直到我的历史记录包含该提交。好像很痛苦的样子...
It is痛苦(而且缓慢,正如您稍后注意到的那样)。
现代 Git(自版本 2.11 起)确实有一个新的git fetch
option:
--shallow-exclude=
Deepen or shorten the history of a shallow repository to
exclude commits reachable from a specified remote branch or tag.
This option can be specified multiple times.
我没有尝试过这个;目前尚不清楚它是否允许哈希 ID(测试使用名称),并且在任何情况下您都会指定父母)您想要深化的提交,而不是您想要的提交obtain。但这可能就足够了。
(我真的认为更好的方法是保留可以借用的参考克隆。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)