如何检索文件的历史记录?
我遇到了另一个 libgit2 问题,非常感谢您的帮助。
我正在尝试检索文件历史记录,即更改此文件的提交列表。这似乎很不传统......据我所知,没有任何功能。
我能想到的唯一方法是使用修订行走 API 来迭代修订,检查附加到提交的树对象并在那里搜索给定文件,如果找到,则将提交添加到我的列表中,否则继续进行下一个提交。
但它对我来说看起来不是最佳的......
可能还有其他方法,例如,直接查看 .git 文件夹并在那里获取所需的信息?
非常感谢!
I got another libgit2 issue and will be very grateful for your help.
I'm trying to retrieve file history, i.e. list of commits where this file was changed. And it seems to be quite unconventional... As far as I can see, there are no function for that.
The only approach I can come up with is to use revision walking API to iterate through revisions, check the tree object attached to commit and search for given file there, if found, add commit to my list, otherwise proceed to next commit.
But it looks none-optimal for me...
May be is there any other approach, for example, look directly into .git folder and get needed information there?
Many thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的方法是正确的。请注意,您必须应对:
尽管了解 .git 文件夹布局总是值得花时间,但恐怕这不会帮助您解决这个特定的文件历史记录问题。
注意:这个问题与这个 libgit2sharp 问题非常接近:How to get the影响给定文件的最后一次提交?
更新
拉取请求#963 添加了这个功能。
它自 LibGit2Sharp.0.22.0-pre20150415174523 预发布 NuGet 包起可用。
Your approach is the correct one. Beware that you'll have to fight against:
Even though understanding the .git folder layout is always a well-spent time, I'm afraid this won't help you with this specific file history issue.
Note: this question is very close from this libgit2sharp issue: How to get the last commit that affected a given file?
Update
Pull request #963 adds this very feature.
It's available since
LibGit2Sharp.0.22.0-pre20150415174523
pre-release NuGet package.这主要是在libgit2的issues/495中遵循的。
即使它是在libgit2sharp中实现的(PR 963,用于 里程碑 22),它在 libgit2 本身中仍然是“待抢夺的”。
该问题记录在 issues/3041:提供包装
revwalk
的日志功能< /a>.问题中提到的方法用于 此 libgit2sharp示例并且可以进行调整使用 libgit2 转换为 C。在 3041 决议得到解决之前,它仍然是当前的解决方法。
This is mainly followed in issues/495 of libgit2.
Even though it is implemented in libgit2sharp (PR 963, for milestone 22), it is still "up for grabs" in libgit2 itself.
The issue is documented in issues/3041: Provide log functionality wrapping the
revwalk
.The approach mentioned in the question was used in this libgit2sharp example and can be adapted to C using libgit2. It remains the current workaround, pending the resolution of 3041.
如果使用 C#,此功能已添加到
LibGit2Sharp
0.22.0 NuGet Package< /a> (拉取请求 963)。您可以执行以下操作:在我的Diff All Files VS Extension中(这是开源的,因此您可以查看代码),我需要获取文件的先前提交,以便我可以看到对文件中的文件进行了哪些更改给定的提交。这就是我检索文件先前提交的方式:
If using C#, this functionality has been added to the
LibGit2Sharp
0.22.0 NuGet Package (Pull Request 963). You can do the following:In my Diff All Files VS Extension (which is open source so you can view the code), I needed to get a file's previous commit so I can see what changes were made to a file in a given commit. This is how I retrieved the file's previous commit: