mtr*_*trc 3 java git github jgit
今天我注册了github,并使用这里描述的技术将现有的文件系统转换为git repo:
最重要的是(我认为)它涉及这一行:
git --bare init
然后我按照github.com的其余设置教程(这是其中的一部分)完成了.现有的文件系统在Dropbox中,所以我在另外两台使用文件系统的机器上执行相同的设置(现在是一个git repo).
今晚我试图让JGit添加一个文件,提交然后推送它.这是代码的要点,直到它破坏为止:
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File("path/to/my/repo"))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
Git git = new Git(repository);
AddCommand add = git.add();
try{
add.addFilepattern("PlayState.as").call();`
Run Code Online (Sandbox Code Playgroud)
顺便提一下,这基本上是从JGit教程逐字逐句采用的.它在最后引用的行引发异常并指出:
org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
at org.eclipse.jgit.lib.Repository.getIndexFile(Repository.java:838)
at org.eclipse.jgit.lib.Repository.lockDirCache(Repository.java:886)
at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:136)
at flipa.FLIPAGame.writeToFlixel(FLIPAGame.java:77)
at flipa.FLIPAGame.main(FLIPAGame.java:58)
Run Code Online (Sandbox Code Playgroud)
现在,我并不是说声称这是不合理的,因为真相被告知我不是版本控制的最好朋友.我得到一个简单的回购是一个只有git in而没有其他文件,但在我看来,现在它有文件.我已经使用终端中的git手动添加,提交并推送到github.所以我不能立即明白为什么它甚至不会认出回购.
任何接受者?
编辑 - 为了澄清,如果有人可以提出另一个解决方案,杀掉这个回购并不是什么大不了的事.我想要一个git repo来使用我的dropbox中的文件系统,并且能够通过Java提交github.
小智 8
对于你的代码,我会说选项setGitdir()和findGitDir()不应该同时使用.要检索现有的存储库,我使用findGitDir(新文件("path/to/my/repo")就足够了.
| 归档时间: |
|
| 查看次数: |
7478 次 |
| 最近记录: |