标签: jgit

使用JGit承诺并推送GitHub - Bare Repo?

今天我注册了github,并使用这里描述的技术将现有的文件系统转换为git repo:

http://crashingdaily.wordpress.com/2009/09/02/initing-a-new-remote-git-repository-with-existing-files/

最重要的是(我认为)它涉及这一行:

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.

java git github jgit

3
推荐指数
1
解决办法
7478
查看次数

应该在gerrit管理的git存储库上定期运行"git gc"吗?

运行cgit是否会定期造成任何伤害(因为gerrit使用JGit操纵repo)?JGit会自动执行此功能吗?

git gerrit jgit

3
推荐指数
1
解决办法
2085
查看次数

添加到repo后无法在eclipse中运行项目.不是一个java项目

我设置了我的github帐户和egit.它工作得很好.我已经学会了升级,提交,推/拉......几乎.

不幸的是(Juno)Eclipse没有将FoobarProstate识别为Java项目.它说FoobarProstate只是一个项目.当我单击绿色运行箭头时,我收到错误消息

无法启动选择,并且最近没有启动.

我在Eclipse中创建了项目,使用File> Import> Git> Git中的Projects从向导中导入它.那可能是我的错.

这是我在Eclipse Package Explorer中看到的.

Eclipse包资源管理器的屏幕截图

我尝试过的:

  • 右键点击项目名称>配置给我一个选择:转换为Maven项目.我不知道那是什么,我不认为我想要那样.

  • 绿色运行下拉箭头>运行方式给我(无适用).

  • 我无法弄清楚将项目更改为java项目的在线说明.

在我在网上找到的答案中,它表示要更改运行配置(绿色运行下拉箭头>运行配置...).但是指令要么不是Juno,要么难以遵循.我真的很困惑.

笔记:

  • 在我的存储库的github视图中,它在这个repo的名字旁边写着"Java"!repo与我的Java项目具有相同的名称(FoobarProstate).

  • 我的FoobarProstate文件存储在C:\ Users\EmilyBB\git\FoobarProstate中.这不是我的Eclipse工作区(C:\ Users\EmilyBB\workspace).那是问题吗?

  • 我刚刚安装了Android东西(ADT等)

谢谢!

eclipse eclipse-plugin github egit jgit

3
推荐指数
1
解决办法
3690
查看次数

JGit:推送到特定分支

我在github上有两个分支:master和development.我想将新创建的文件推送到开发分支.

    String user = "user";
    String password = "password";
    String localPath = "local";
    String remotePath = "https://github.com/some/git.git";
    Git.cloneRepository().setBranch("refs/heads/development").setURI(remotePath).setDirectory(new File(localPath)).call();
    Git localGit = Git.open(new File(localPath));         
    localGit.checkout().setName("origin/development").setUpstreamMode(SetupUpstreamMode.TRACK).call();

    new File("local/test").createNewFile();

    localGit.add().addFilepattern(".").call();
    localGit.commit().setMessage("message").call();
    localGit.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).call();
Run Code Online (Sandbox Code Playgroud)

我得到的是一个

  TransportException: Nothing to push.
Run Code Online (Sandbox Code Playgroud)

有什么问题?

更新: 我可以通过删除checkout命令使其工作.由于克隆已经检出指定的分支,这在我之前并不清楚.

git branch push jgit

3
推荐指数
1
解决办法
2721
查看次数

如何在JGit中重命名文件

如何在JGit中重命名文件.也就是说,给定一个名为file1的工作文件.

命令行将是:

git mv file1 file2
Run Code Online (Sandbox Code Playgroud)

rename file-rename jgit

3
推荐指数
1
解决办法
707
查看次数

使用JGit确定前后的提交次数

在GitHub项目上,当我们转到任何分支页面时,我们都可以看到描述分支wrt master前面/后面编号的图形。

我们如何使用JGit确定数字后面的那些?

BranchTrackingStatus为此使用了类,但是我得到的BranchTrackingStatus对象始终为null。

这是我使用的代码

private static Lis<Integer> getCounts(Repository repository, String branchName) throws IOException{
  BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branchName);
  List<Integer> counts = new ArrayList<Integer>();
  if (trackingStatus != null){
      counts.add(trackingStatus.getAheadCount());
      counts.add(trackingStatus.getBehindCount());
  } else {
      counts.add(0);
      counts.add(0);
  }
  return counts;
}

public void show(String repoName, String baseBranchName) throws IOException, GitAPIException{    

  Repository repository = repoManager.openRepository(new Project.NameKey(repoName));

  List<Ref> call = new Git(repository).branchList().call();
  for (Ref ref : call) {
    List<Integer> counts = getCounts(repository, ref.getName());
    System.out.println("Commits ahead : "+counts.get(0));
    System.out.println("Commits behind : …
Run Code Online (Sandbox Code Playgroud)

jgit

3
推荐指数
1
解决办法
1346
查看次数

如何在裸存储库中使用JGit暂存文件?

我阅读了在非裸存储库中暂存文件问题和答案.但是,我正在使用裸存储库,我想要暂存文件.

我尝试使用DirCacheBuilder测试,但代码Repository.lockDirCache()Repository.readDirCache()失败,因为这是一个裸存储库.

org.eclipse.jgit.errors.NoWorkTreeException:Bare Repository在org.eclipse.jgit.dircache.DirCache上既没有工作树,也没有org.eclipse.jgit.lib.Repository.getIndexFile(Repository.java:993)的索引. .read(DirCache.java:166)org.eclipse.jgit.lib.Repository.readDirCache(Repository.java:1017)

那么,我怎样才能使用JGit在裸存储库中暂存文件?这有可能吗?

java git jgit

3
推荐指数
1
解决办法
559
查看次数

如何用JGit确定哪些分支已合并为master?

如何使用JGit确定哪些分支已合并为主分支?

我想做相当于普通的git命令:

git branch -a --merged
Run Code Online (Sandbox Code Playgroud)

这在JGit中可行吗?

jgit

3
推荐指数
1
解决办法
1278
查看次数

使用JGit在提交之间更改的文件列表

我想在两次提交之间更改(添加,修改或删除)文件的路径.

从命令行,我只是写

git diff --name-only abc123..def456
Run Code Online (Sandbox Code Playgroud)

使用JGit执行此操作的等效方法是什么?

java git-diff jgit

3
推荐指数
1
解决办法
2216
查看次数

如何使用JGit将已删除的文件添加到索引中?

我想在索引中添加所有在文件夹中进行的修改:

  • 文件已修改
  • 文件已添加
  • 文件已删除
File gitDir = new File("/home/franck/Repositories/Git/Sandbox/.git");
try (Repository repo = new RepositoryBuilder().setGitDir(gitDir).build()){
    try (Git git = new Git(repo)){
        final Status status = git.status().addPath("testGit").call();
        final AddCommand addCommand = git.add();

        Set<String> removed = status.getRemoved();
        for (final String s : removed) {
            System.out.print("removed: "+s);
            addCommand.addFilepattern(s);
        }

        Set<String> missing =  status.getMissing();
        for (final String s : missing) {
            System.out.print("Missing: "+s);
            addCommand.addFilepattern(s);
        }

        addCommand.call();
    }
}
Run Code Online (Sandbox Code Playgroud)

输出此命令:

Missing: testGit/test.txt
Run Code Online (Sandbox Code Playgroud)

并输出git status:

On branch master  
Your branch is ahead of 'origin/master' …
Run Code Online (Sandbox Code Playgroud)

jgit

3
推荐指数
1
解决办法
1905
查看次数

标签 统计

jgit ×10

git ×4

java ×3

github ×2

branch ×1

eclipse ×1

eclipse-plugin ×1

egit ×1

file-rename ×1

gerrit ×1

git-diff ×1

push ×1

rename ×1