Tag: jgit

用JGIT浅克隆

我该怎么办 git clone –depth 1 … 与JGIT库?

使用JGit键可以安全地访问Git存储库

我正在使用JGit访问远程Git仓库,我需要使用SSH 。 JGit使用JSch提供安全访问。 但是,我不确定如何为JGit设置密钥文件和知道的hosts文件。 我试过的如下。 使用子类化JSchConfigSessionFactory创建SshSessionFactory的自定义配置: public class CustomJschConfigSessionFactory extends JschConfigSessionFactory { @Override protected void configure(OpenSshConfig.Host host, Session session) { session.setConfig(“StrictHostKeyChecking”, “yes”); } } 在我访问远程Git仓库的类中,执行以下操作: CustomJschConfigSessionFactory jschConfigSessionFactory = new CustomJschConfigSessionFactory(); JSch jsch = new JSch(); try { jsch.addIdentity(“.ssh/id_rsa”); jsch.setKnownHosts(“.ssh/known_hosts”); } catch (JSchException e) { e.printStackTrace(); } SshSessionFactory.setInstance(jschConfigSessionFactory); 我无法弄清楚如何将此JSch对象与JGit关联,以便它可以成功连接到远程存储库。 当我尝试使用JGit克隆它时,我得到以下exception: org.eclipse.jgit.api.errors.TransportException: git@git.test.com:abc.org/test_repo.git: reject HostKey: git.test.com at […]

如何在JGit中“捕捉”文件?

前段时间我正在寻找一个Java嵌入式分布式版本控制系统 ,我想我已经在JGit中找到了它,它是git的纯Java实现。 但是,示例代码或教程的方式并不多。 如何使用JGit检索某个文件的HEAD版本(就像svn cat或hg cat那样)? 我想这涉及一些转树行走,我正在寻找代码示例。

如何使用JGit显示提交之间的更改

我试图在文件的两个提交之间显示一个git diff。 基本上,我是在https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ShowChangedFilesBetweenCommits.java中做到的。 您可以在https://github.com/svenhornberg/JGitDiff下查看我的完整代码 public class RepoDiff { public void compare(byte[] fileContentOld, byte[] fileContentNew) { try { Repository repository = createNewRepository(); Git git = new Git(repository); // create the file commitFileContent(fileContentOld, repository, git, true); commitFileContent(fileContentNew, repository, git, false); // The {tree} will return the underlying tree-id instead of the commit-id itself! ObjectId oldHead = repository.resolve(“HEAD^^^^{tree}”); […]