Tag: java

JGit detect rename in working copy

Contex I’m trying to detect possible file rename that occurred after last commit, in a working copy. On my example, I have a clean working copy and I do that: git mv old.txt new.txt Running $ git status shows the expected result: # Changes to be committed: # (use “git reset HEAD <file>…” to unstage) […]

How to restore shelved changes in Intellij when the shelf tab is not shown?

I tried to use the “shelf” feature for the first time in IntelliJ IDEA today. I shelved all my current changes so that I could work on a quick bugfix, commit it, and come back to my current work afterwards. When I commited the “shelf” action, IntelliJ created the shelf and I could see it […]

Retrieving oldest commit with JGit

I am experimenting with JGit for a project and while it mostly works, retrieving the oldest (first) commit does not. Here is the code: RevWalk rw = new RevWalk(new Repository( new File(“/path/to/git”))); RevCommit oldest; Iterator<RevCommit> i = rw.iterator(); if (i.hasNext()) oldest = i.next(); Commit c = oldest.asCommit(rw); //oldest is null here, NPE Does anyone know […]

Found a swap file by the name “.git/.MERGE_MSG.swp”

I tried to pull origin branschName and got this strange error: error: There was a problem with the editor ‘vi’. Not committing merge; use ‘git commit’ to complete the merge. E325: ATTENTION Found a swap file by the name “.git/.MERGE_MSG.swp” owned by: eladb dated: Tue Aug 20 10:52:03 2013 file name: ~eladb/MyWorkspace/Client/.git/MERGE_MSG modified: no user […]

How to import a local GIT/Maven project/folder into eclipse?

So I did git clone to get a maven project from a remote git repository. Great! I have been working in the command line, doing git pull, commit, etc. Great! Now I want to import this project into eclipse and be able to use git inside eclipse through the installed egit. So I did a: […]

How is a merge-base done in JGit?

I’m looking at the JGit Documentation, currently at version, and I cannot find the equivalent of git-merge-base. I would like to determine if a branch is up-to-date, behind, ahead, or diverged, as shown in git: check if pull needed. What is the most concise way in JGit to find as good common ancestors as […]

Getting all branches with JGit

How can I get all branches in a repository with JGit? Let’s take an example repository. As we can see, it has 5 branches. Here I found this example: int c = 0; List<Ref> call = new Git(repository).branchList().call(); for (Ref ref : call) { System.out.println(“Branch: ” + ref + ” ” + ref.getName() + ” […]

Specifying ssh key for jgit

I’m wondering how I can use jgit to connect to github using a specified ssh key file (i.e. one not in ~/.ssh/). Unfortunately, I’m not sure how to use JschConfigSessionFactory properly. I’ve tried creating a setup just like the one in this article: Using Keys with JGit to Access a Git Repository Securely I call […]

How to do a git pull with an in-memory database in JGit?

I want to create a Java program, which connects to a certain Git repository, appends text to a file, commits and pushes the changes to that repository. Ideally, all of this should happen in the memory. I’m using JGit for interaction with Git: InMemoryRepository repo = new InMemoryRepository(new DfsRepositoryDescription()); Git git = new Git(repo); git.init().call(); […]

Intellij: Making a project dependent on another project?

I am new to using Intellij and I am facing a problem. I have a project, which is dependent on another project and this second project is integrated using maven repository. So when I work on my project, maven handles everything perfectly and everything is working. But the second project is under development and there […]

Git Baby is a git and github fan, let's start git clone.