【发布时间】:2017-10-03 06:47:12
【问题描述】:
我在一个 CI 盒子上运行测试。为了加快速度,我只是在做一个浅克隆:
git clone --depth 1 git@github.com: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,直到我的历史记录包含提交。这看起来很痛苦(意味着编写/维护很烦人)和昂贵的(意味着慢,记住浅克隆的目的是降低这个成本)。
【问题讨论】:
标签: git git-diff git-remote git-fetch