2012-02-21 58 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() 
    ... 
}