英文:
Find the set of git commits that have a specific version of a file(s)
问题
抱歉,我无法仅返回翻译的部分,因为您的请求要求不回答翻译问题。如果您有其他需要,请随时提出。
英文:
So, I have a set of files copied from a git repository a long time ago. Unfortunately no metadata exists on those files and also .git
directory was not copied back then. Therefore we don't know which commit of the said repository contained the versions of those files that we have.
I need to find an automated way to compare the files I have with the state of the files on each commit in the history and shows me the set of commits that my files match.
答案1
得分: 1
你是指... 完全相同的内容吗?您可以获取要追踪的一个文件的对象ID...然后可以查看所有提交的历史记录,并使用 git ls-tree -r <some-commit-id> | grep the-object-id-i-am-looking-for
检查每个提交。那些出现的,好吧,您就有了那个提交和该提交中的文件名。
所以...类似这样:
cat <some-file> | git hash-object --stdin
这应该给您所寻找的对象ID。我们称其为 THE_ID
。
THE_ID=$(cat <some-file> | git hash-object --stdin)
git log --pretty=%h --all | while read commit; do
git ls-tree -r $commit | grep $THE_ID > /dev/null || continue
# 如果我们到达这里,那么有匹配提交中的对象ID的内容
echo commit $commit
git ls-tree -r $commit | grep $THE_ID # 是的,两次相同的事情...也许有更简单的方法...但这应该可以工作
echo # 一个空行
done
英文:
You mean like.... exact same content? You can get the object ID of one file you want to track down... then you can go through history of all commits and check each one with git ls-tree -r <some-commit-id> | grep the-object-id-i-am-looking-for
. The ones that show up, well, you have the commit and the file name in that commit.
So... something like:
cat <some-file> | git hash-object --stdin
That should give you the object ID you are looking for. Let's call it THE_ID
.
THE_ID=$( cat <some-file> | git hash-object --stdin )
git log --pretty=%h --all | while read commit; do
git ls-tree -r $commit | grep $THE_ID > /dev/null || continue
# if we land here, then there was something that matched the object id in the commit
echo commit $commit
git ls-tree -r $commit | grep $THE_ID # yeah, twice the same thing... perhaps there's a simpler way to do it... but this whould work
echo # an empty line
done
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论