查找具有特定文件版本的git提交集。

huangapple go评论56阅读模式
英文:

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 &lt;some-commit-id&gt; | 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 &lt;some-file&gt; | git hash-object --stdin

That should give you the object ID you are looking for. Let's call it THE_ID.

THE_ID=$( cat &lt;some-file&gt; | git hash-object --stdin )
git log --pretty=%h --all | while read commit; do
    git ls-tree -r $commit | grep $THE_ID &gt; /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&#39;s a simpler way to do it... but this whould work
    echo # an empty line
done

huangapple
  • 本文由 发表于 2023年7月13日 18:37:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678422.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定