2016-05-03 8 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, у меня есть более чем один совершает для файла. Как я могу получить статус/действие для этого commit.I означает, как я могу узнать о конкретном коммите, является ли этот файл добавлен или он был изменен или он был помечен. Я хочу, чтобы правильный API eclipse получите вышеуказанные данные.

+0

могли бы вы объяснить подробнее? – Alice

+0

Как они отображаются в столбце состояния прикрепленного изображения, я хочу получить API в JGIT –

+0

Вы проверили http://stackoverflow.com/questions/23508315/git-status-does-not-show-changes-when-creating -repo-in-jgit – Alice

ответ

0

Get мерзавец файл состояния с помощью 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()); 
      }