2012-02-21 63 views
0

基本上我需要在版本库中获取旧版本的文件,而无需更改当前的工作文件。 我想不同的方式:使用ngit获取旧版本的文件内容

  • 临时党支部和做的事
  • 复制文件,签文件做我的事,并将其返回

但这些方法真的是缓慢而复杂的。是不是有比ngit更简单的东西?

+0

是否必须ngit? 'git show :path/to/file> file.old-version'(或者我猜可能是ngit有一个git-show模拟?) – Cascabel 2012-02-21 17:50:58

+0

[git-cat-file](http://schacon.github.com/ git/git-cat-file.html)也是一个选择。 [git show回答here](http://stackoverflow.com/questions/610208/how-to-retrieve-a-single-file-from-specific-revision-in-git)完全 – 2012-02-21 18:48:06

+0

谢谢你们,但我们的产品是使用已经的ngit,这将是一个相当努力的改变一切。那么,我可以尝试包装控制台,因为这个唯一的原因,但我仍然希望得到一个ngit解决方案:) – 2012-02-21 19:13:27

回答

0

使用NGit:该方法使用的详细信息,请参阅jgit文档http://jgit.info/javadoc/

ObjectId commitId = git.GetRepository().Resolve(ref); 
RevWalk revWalk = new RevWalk(git.GetRepository()); 
RevTree revTree = loRevWalk.ParseTree(commitId); 
TreeWalk treeWalk = new TreeWalk(git.GetRepository()); 
treeWalk.AddTree(revTree); 

while (treeWalk.Next()) 
{ 
    //compare treeWalk.NameString yourself 
    byte[] bytes = treeWalk.ObjectReader.Open(treeWalk.GetObjectId(0)).GetCachedBytes() 
    ... 
}