위의 로직을 구현하여 내 파일 만 포함하는 새 커밋 (부모 없음)을 만듭니다. 커밋은 저장소에서 빠르다. CommitCommand commit = git.commit();
BLOG로 커밋 할 때 jgit에 파일 로그 표시
그러나 특정 파일의 로그, 업데이트/수정 횟수, 그리고 내가 Constants.HEAD
으로 갈 때마다 나는 얻을 수 없다. 없는.
도움이 될 것입니다.
Git git = jGitUtil.openRepo();
Repository repository = git.getRepository();
ObjectInserter repoInserter = repository.newObjectInserter();
ObjectId commitId = null;
try
{
byte[] fileBytes= FileUtils.readFileToByteArray(sourceFile);
// Add a blob to the repository
ObjectId blobId = repoInserter.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, fileBytes);
// Create a tree that contains the blob as file "hello.txt"
TreeFormatter treeFormatter = new TreeFormatter();
treeFormatter.append(actualFileName, FileMode.REGULAR_FILE, blobId);
ObjectId treeId = treeFormatter.insertTo(repoInserter);
System.out.println("File comment : " + relativePath + PortalConstants.FILESEPARATOR + actualFileName + PortalConstants.EP_DELIMETER + userComments);
// Create a commit that contains this tree
CommitBuilder commit = new CommitBuilder();
PersonIdent ident = new PersonIdent(user.getFirstName(), user.getUserId());
commit.setCommitter(ident);
commit.setAuthor(ident);
commit.setMessage(relativePath + PortalConstants.FILESEPARATOR + actualFileName + PortalConstants.EP_DELIMETER + userComments);
commit.setTreeId(treeId);
commitId = repoInserter.insert(commit);
System.out.println(" commitId : " + commitId.getName());
repoInserter.flush();
System.out.println("Flush Done");
}catch(IOException ioe){
log.logError(StackTraceUtil.getStackTrace(ioe));
System.out.println(StackTraceUtil.getStackTrace(ioe));
}
finally
{
repoInserter.release();
}
return commitId.getName();
}
잘 모르겠습니다. https://github.com/centic9/jgit-cookbook에있는 샘플 중 어떤 것이 도움이됩니까? – centic
안녕하세요 Centic, 당신의지도에 감사드립니다. 너에게 올린 링크에서 모든 발췌 문장을 시도했다. 나는 아무 머리 예외도 얻는 것을 계속하지 않는다. 더 나은 통찰력을 위해 내 커밋 코드 스 니펫을 올리려고합니다. – user2526935