如何检索文件的历史记录? [英] How to retrieve the history of a file?

查看:141
本文介绍了如何检索文件的历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试检索文件历史记录,即该文件发生更改的提交列表。它似乎是非常规的......就我所知,没有这个功能。



我能想到的唯一方法是使用修改漫游API以遍历修订版本,检查附加的树对象提交并在那里搜索给定文件,如果找到,将提交添加到我的列表中,否则继续执行下一个提交。



但它对我来说看起来并不是最佳的......

可能有其他方法,例如,直接看 .git 文件夹并获取需要的信息吗?



非常感谢您提前!


但是它对我来说看起来不是最理想的......


您的方法是正确的。请注意,您必须与以下各项作斗争:




  • 简单重命名(同一对象哈希,不同的树条目名称)

  • 在同一个提交中重命名和内容更新(不同的哈希,不同的树条目名称,需要libgit2中没有的文件内容分析和比较功能)
  • 多个父母的历史(两个分支已合并,并以不同的方式修改了相同的文件)



可能还有其他方法,例如,直接查看.git文件夹并获取所需信息吗?

偶数尽管了解.git文件夹布局总是一个很好的时间,但恐怕这不会帮助你解决这个特定的文件历史问题。



注意:这个问题与这个libgit2sharp问题非常接近:如何获取影响给定文件的最后一次提交?



更新



提取请求 #963 增加了此功能。

LibGit2Sharp.0.22.0-pre20150415174523 预发布NuGet软件包后可用。


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!

解决方案

But it looks none-optimal for me...

Your approach is the correct one. Beware that you'll have to fight against:

  • Plain renaming (same object Hash, different tree entry name)
  • Renaming and content updation occuring in the same commit (Different hash, different tree entry name. Would require file content analysis and comparison feature which is not available in libgit2)
  • Multiple parents history (two branches which have been merged and into which the same file has been modified in a different way)

May be is there any other approach, for example, look directly into .git folder and get needed information there?

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.

这篇关于如何检索文件的历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆