jgit

How to “cat” a file in JGit?

冷暖自知 提交于 2019-11-26 22:43:28
问题 A while back I was looking for an embeddable distributed version control system in Java, and I think I have found it in JGit, which is a pure Java implementation of git. However, there is not much in the way of sample code or tutorials. How can I use JGit to retrieve the HEAD version of a certain file (just like svn cat or hg cat whould do)? I suppose this involves some rev-tree-walking and am looking for a code sample. 回答1: Unfortunately Thilo's answer does not work with the latest JGit API.

Using Keys with JGit to Access a Git Repository Securely

£可爱£侵袭症+ 提交于 2019-11-26 20:00:52
问题 I'm using JGit to access a remote Git repo, and I need to use SSH for it. JGit uses JSch to provide secure access. However, I'm not sure how to set the key file and the knows hosts file for JGit. What I have tried is as follows. Created a custom configuration of the SshSessionFactory, using by subclassing JSchConfigSessionFactory: public class CustomJschConfigSessionFactory extends JschConfigSessionFactory { @Override protected void configure(OpenSshConfig.Host host, Session session) {

How to show changes between commits with JGit

◇◆丶佛笑我妖孽 提交于 2019-11-26 08:35:16
问题 I am trying to show a git diff between two commits for a file. Basically, I did it as in https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ShowChangedFilesBetweenCommits.java You can see my full code under 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