我嘗試了很多方法來使用jGit克隆回購(它有效)。 然後,我在存儲庫中寫入一些存檔,並嘗試添加所有(git add *
,git add -A
或類似的東西)..但它不起作用。簡單的文件不會被添加到暫存區域。jGit - 如何將所有文件添加到分段區域
我的代碼是這樣的:
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(folder))
.readEnvironment().findGitDir().setup().build();
CloneCommand clone = Git.cloneRepository();
clone.setBare(false).setCloneAllBranches(true);
clone.setDirectory(f).setURI("[email protected]:test.git");
try {
clone.call();
} catch (GitAPIException e) {
e.printStackTrace();
}
Files.write("testing it...", new File(folder + "/test2.txt"),
Charsets.UTF_8);
Git g = new Git(repository);
g.add().addFilepattern("*").call();
我在做什麼錯? 謝謝。
異常而與addFilePattern想什麼( 「」):
Exception in thread "main" org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
at org.eclipse.jgit.lib.Repository.getIndexFile(Repository.java:850)
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:264)
at org.eclipse.jgit.lib.Repository.lockDirCache(Repository.java:906)
at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:138)
at net.ciphersec.git.GitTests.main(GitTests.java:110)
謝謝,但我得到了一個異常。我會把它放在這個問題 – caarlos0
@ caarlos0回答編輯 – VonC
但我克隆它作爲一個非裸存儲庫...我不明白我應該這樣做... – caarlos0