JGit and finding the Head

后端 未结 4 1922
名媛妹妹
名媛妹妹 2021-01-01 10:23

I\'m trying to get my hands on the HEAD commit with JGit:

val builder = new FileRepositoryBuilder()
val repo = builder.setGitDir(new File(\"/www/test-repo\")         


        
4条回答
  •  时光取名叫无心
    2021-01-01 11:10

    For the completeness sake, here is a fully working example how to get the hash for the HEAD commit:

    public String getHeadName(Repository repo) {
      String result = null;
      try {
        ObjectId id = repo.resolve(Constants.HEAD);
        result = id.getName();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return result;
    }
    

提交回复
热议问题