2016-05-03 7 views
-1

In TortoiseGit GUI,if we show log for a commit it is displaying the status as added since this file is added newly at that commit[![In this ,as i modified the file ,in status column it is showing as modified アクションはgitの中で私の地元のgitリポジトリで

をコミット特定のために行われています、私は1つのファイルに対してコミットする以上のものを持っています。どのようにステータス/アクションを取得することができますコミット。私は、特定のコミットを知ることができますか、そのファイルが新しく追加されたか、それが変更されているか、上記の詳細を取得します。

+0

を使用してgitのファイルのステータスを取得し、あなたはより多くを説明してくださいだろうか? – Alice

+0

添付画像のステータス欄に表示されるので、JGITでAPIを取得したい –

+0

http://stackoverflow.com/questions/23508315/git-status-does-not-show-changes-when-creatingをチェックしましたか? -repo-in-jgit – Alice

答えて

0

JGit

 // find the HEAD 
     ObjectId lastCommitId = existingRepo.resolve(Constants.HEAD); 

     // a RevWalk allows to walk over commits based on some filtering that is defined 
     try (RevWalk revWalk = new RevWalk(existingRepo)) { 
      RevCommit commit = revWalk.parseCommit(lastCommitId); 
      // and using commit's tree find the path 
      RevTree tree = commit.getTree(); 

      // now try to find a specific file 
      try (TreeWalk treeWalk = new TreeWalk(existingRepo)) { 
       treeWalk.addTree(tree); 
       treeWalk.setRecursive(true); 
       treeWalk.setFilter(PathFilter.create("TestProject/test1")); 
       if (!treeWalk.next()) { 
        throw new IllegalStateException("Did not find expected file"); 
       } 

       ObjectId objectId = treeWalk.getObjectId(0); 
       ObjectLoader loader = existingRepo.open(objectId); 

       // and then one can the loader to read the file 
       loader.copyTo(System.out); 

       // Get status 
       Git git = new Git(existingRepo); 
       StatusCommand status = git.status().addPath(treeWalk.getPathString()); 
       System.out.println("Not Modified : " + status.call().getModified().isEmpty()); 
      } 
関連する問題