jgit

Get the latest commit in a repository with JGit

可紊 提交于 2019-12-20 01:17:47
问题 I want to get the last commit metadata (the youngest one by date) in a repository using JGit. I know that I can get the commit metadata using try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(repository.resolve(commitHash)); } But how to get the latest commit hash? Is there any other way to get the youngest by date RevCommit in a repository directly? 回答1: Compare by dates of last commits in all branches. ListMode.ALL can be changed to ListMode.REMOTE to

How to merge in JGit?

扶醉桌前 提交于 2019-12-19 13:50:08
问题 How do I merge in JGit? Let's say I want to merge master with foo branch, how do I do this? 回答1: To merge, you can use the MergeCommand (in package org.eclipse.jgit.api), after a CheckoutCommand . To provide you with an example, because indeed Jgit lacks examples: Git git = ... // you get it through a CloneCommand, InitCommand // or through the file system CheckoutCommand coCmd = git.checkout(); // Commands are part of the api module, which include git-like calls coCmd.setName("master");

How do I do git push with JGit?

青春壹個敷衍的年華 提交于 2019-12-18 11:52:56
问题 I'm trying to build a Java application that allows users to use Git based repositories. I was able to do this from the command-line, using the following commands: git init <create some files> git add . git commit git remote add <remote repository name> <remote repository URI> git push -u <remote repository name> master This allowed me to create, add and commit content to my local repository and push contents to the remote repository. I am now trying to do the same thing in my Java code, using

How to determine with JGit which branches have been merged to master?

匆匆过客 提交于 2019-12-18 08:59:05
问题 How do I use JGit to determine which branches have been merged to master? I want to do the equivalent of the normal git command: git branch -a --merged Is this possible in JGit? 回答1: RevWalk::isMergedInto() can be used to determine if a commit was merged into another. That is, isMergedInto returns true if the commit given in the first argument is an ancestor of the second given commit. try( RevWalk revWalk = new RevWalk( repository ) ) { RevCommit masterHead = revWalk.parseCommit( repository

Shallow clone with JGIT

老子叫甜甜 提交于 2019-12-18 03:54:53
问题 How I can do git clone --depth 1 ... with JGIT library? 回答1: You can't, JGit doesn't yet support shallow clones on the client side (it does on the server side, though). 来源: https://stackoverflow.com/questions/11475263/shallow-clone-with-jgit

Is it possible to slim a .git repository without rewriting history?

蓝咒 提交于 2019-12-18 02:19:35
问题 We have a number of git repositories which have grown to an unmanageable size due to the historical inclusion of binary test files and java .jar files. We are just about to go through the exercise of git filter-branch ing these repositories, re-cloning them everywhere they are used (from dozens to hundreds of deployments each, depending on the repo) and given the problems with rewriting history I was wondering if there might be any other solutions. Ideally I would like to externalise problem

How to use jgit to clone the existing repositories to new github instance?

一世执手 提交于 2019-12-13 21:04:43
问题 We have two separate GitHub instance running. One GitHub instance is https://github.dev.host.com and other github instance is https://github.host.com . I have various repositories in https://github.dev.host.com which I need to migrate to this new github instance https://github.host.com . I am using JGit as I am working with Java. For example - Below are the repositories that are present in https://github.dev.host.com instance which I need to migrate to new github instance https://github.host

How do I do the equivalent of “git remote update” with jgit?

落花浮王杯 提交于 2019-12-13 16:16:37
问题 I'm managing git repos cloned with --mirror, and I need to do a git remote update using JGit. Do I use a FetchCommand, or is there any other command? What is the equivalent FetchCommand of a git remote update ? 回答1: You should use FetchCommand and call setRemote to specify the name of the remote you want to fetch from. If you have multiple remotes you want to fetch from, create a new FetchCommand instance for each remote you are fetching from. 来源: https://stackoverflow.com/questions/9594827

JGit : How to get Branch when traversing repos

Deadly 提交于 2019-12-12 10:38:34
问题 The lacking JGit docs dont seem to say anything about how to use/detect branches while using a RevWalk. This question says pretty much the same thing. So my question is: How do I get the branch name/id from a RevCommit? Or how do I specify which branch to traverse before hand? 回答1: Found out a better way to do it by looping branches. I looped over the branches by calling for (Ref branch : git.branchList().call()){ git.checkout().setName(branch.getName()).call(); // Then just revwalk as normal

Checkout a specific revision based on the commit date with JGit

99封情书 提交于 2019-12-12 06:07:13
问题 I want to use the Java JGit library in order to retrieve previously committed revisions of a file. The file gets updated on a daily basis and I need to have access to the previous versions from a git repository. I know how to checkout a specific revision by providing the commit hash of the revision I need, as described here with this command: git.checkout().setName( "<id-to-commit>" ).call(); Currently I clone the repository, search for the most recent commit of that file and then checkout