我知道 JGit 中对 git 子模块的支持是有限的,但仍然想知道如何实现这一点:
git submodule foreach git checkout <branchName>
以及使用 JGit 的类似命令。
或者还有其他更好的基于 Java 的 Git API 吗?
我正在用egit做一个rebase,并且有一个冲突,例如popt up下面的对话框

我不清楚这两个选项是什么.我的问题是.
我只想从 Git 存储库中检索提交日志,其中包含您在特定存储库上所做的所有提交的消息。我找到了一些代码片段来实现这一点,并以一个例外结束。
try {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setGitDir(new File("https://github.com/name/repository.git")).readEnvironment().findGitDir().build();
RevWalk walk =new RevWalk(repo);
ObjectId head = repo.resolve(Constants.HEAD);
RevCommit commit =walk.parseCommit(head);
Git git =new Git(repo);
Iterable<RevCommit> gitLog = git.log().call();
Iterator<RevCommit> it = gitLog.iterator();
while(it.hasNext())
{
RevCommit logMessage = it.next();
System.out.println(logMessage.getFullMessage());
}
}
catch(Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
但是它给了我:
org.eclipse.jgit.api.errors.NoHeadException: No HEAD exists and no explicit starting revision was specified exception.
Run Code Online (Sandbox Code Playgroud)
我该如何摆脱这个?我正在使用 org.eclipse.jgit JAR 版本 2.0.0.201206130900-r
当我git show commit在存储库中进行第一次提交时,我会看到所有文件以及文件的差异(即添加的所有行)
$ git show cb5d132
commit cb5d13286cf9d14782f0e10445456dfe41072f55
Author: tw2 tw2LastName <tw2>
Date: Thu Oct 23 05:15:09 2014 -0400
Initial Commit
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..96d156e
--- /dev/null
+++ b/README.txt
@@ -0,0 +1 @@
+First Line in README file!
\ No newline at end of file
Run Code Online (Sandbox Code Playgroud)
似乎jgit show没有获得类似的信息,如何使用 JGit API 获得类似的输出?我可以使用DiffFormatter,但它似乎需要 baseTree 和 commitTree,想知道如何让它们DiffFormatter在存储库中的第一次提交上工作。
ByteArrayOutputStream os = new ByteArrayOutputStream();
DiffFormatter df = new DiffFormatter( os ) …Run Code Online (Sandbox Code Playgroud) 我正在使用 Jgit 3.7 从 Git 存储库导入文件。但我想只导入一组文件夹而不是全部。我知道 Git 支持这个,但我想知道 Jgit 3.7 支持同样的吗?如果是这样,有人可以指导我吗?
我正在使用 jgit 进行自动化,我想问一下 jgit 上是否可以使用 gpg 签名。我还没有在网上找到实现。
如果它仍然不可用,您能否推荐一个实现为 git 自动执行 gpg 签名?
我想将远程私有Atlassian BitBucket存储库克隆到我的计算机。
您能否描述一下该过程如何完成。
我对身份验证过程特别感兴趣。我是否需要使用Atlassian BitBucket(对于Atlassian BitBucket)UsernamePasswordCredentialsProvider作为CredentialsProvider它,或者应该执行一些其他步骤才能做到这一点?
更新
我尝试了以下解决方案:
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(Host host, Session session) {
session.setPassword( "password" );
session.setConfig("StrictHostKeyChecking", "no");
}
};
CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setURI("ssh://user@bitbucket.org/reponame.git");
//cloneCommand.setURI("git@bitbucket.org:user/reponame.git");
cloneCommand.setDirectory(new File("reponame"));
cloneCommand.setTransportConfigCallback(new TransportConfigCallback() {
@Override
public void configure(Transport transport) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
}
});
cloneCommand.call();
Run Code Online (Sandbox Code Playgroud)
但失败,但以下异常:
Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: git@bitbucket.org:user/reponame.git: Auth fail
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:248)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:200)
at com.bitbucket.BitBucketTest.cloneViaSsh(BitBucketTest.java:63)
at com.bitbucket.BitBucketTest.main(BitBucketTest.java:39)
Caused by: …Run Code Online (Sandbox Code Playgroud) 我想以编程方式更新HEAD而不对非裸仓库执行checkout或rebase.
我希望工作树和索引在操作后保持不变.
编辑
我需要更新HEAD的符号目标,而不是HEAD当前目标的提交ID.这更像是一个结账,而不是其他任何东西,除了我不能使用,org.eclipse.jgit.api.CheckoutCommand因为它要求我更新路径,但我不想触摸工作树.org.eclipse.jgit.api.CreateBranchCommand也是不合适的,因为它期望一个特定的起点,因为我正在创建一个孤儿分支而不存在.
或者只是两个日期之间发生的所有提交?在SVN中,您可以做类似svn diff -r{date}:{date}的事情!
我在E中创建了一个目录,命名为gitrepo full path is(E:\ gitrepo)之后我用以下代码克隆了一个存储库
Git git=Git.cloneRepository()
.setURI("samplelink.git")
.setDirectory(new File("/E:/gitrepo"))
.call();
Run Code Online (Sandbox Code Playgroud)
然后我用这段代码打开了一个存储库
public Repository openRepository() throws IOException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File("/E:/gitrepo"))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
log.info("Repository directory is {}", repository.getDirectory());
return repository;
}
Run Code Online (Sandbox Code Playgroud)
一切正常,直到这里我试图在这个本地存储库中添加一个文件
Repository repo = openRepository();
Git git = new Git(repo);
File myfile = new File(repo.getDirectory()/*.getParent()*/, "testfile");
if (!myfile.createNewFile()) {
throw new IOException("Could not create file " + myfile);
} …Run Code Online (Sandbox Code Playgroud)