2016-05-03 3 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 obtenir l'action a été réalisée pour notamment dans git commit

Dans mon dépôt git local, j'ai plus d'un engage pour un fichier. Comment puis-je obtenir le statut/action a été effectuée sur ce commit.I signifie, comment puis-je savoir sur un commit particulier, est ce fichier nouvellement ajouté ou est-il modifié ou est-il marqué .. je veux l'API eclipse correcte à obtenir les détails ci-dessus.

+0

pourriez-vous s'il vous plaît expliquer plus? – Alice

+0

Comme ils montrent dans la colonne de statut de l'image ci-jointe, je veux obtenir l'API dans JGIT –

+0

avez-vous vérifié http://stackoverflow.com/questions/23508315/git-status-does-not-show-changes-when-creating -repo-in-jgit – Alice

Répondre

0

obtenir le statut de fichier git en utilisant 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()); 
      }