git add *
、git add -A
或类似命令)...但是它不起作用。这些文件根本没有被添加到暂存区。
我的代码如下: 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("git@192.168.2.43: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)
Git git = cloneCmd.call()
,并使用这个git实例来管理事情...谢谢@vonc - caarlos0git.add().addFilepattern("sub").setUpdate(true).call();
更好吗?(https://github.com/eclipse/jgit/blob/2ab42b74d9803d8239ff4f9eda1cf153666a4079/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java#L676-L679) - VonC