0

I'm trying to implement a git repository with just one branch (no other branches allowed). So I tried to do something like the following:

     git rm -r -f *
     git checkout <hash> .

     *** make changes you want ***
    
     git stage -A
     git commit -m <commit message>

Which works totally fine for me when using it by the console. However when using jgit I'm struggeling to implement the "git checkout <hash> ." part, since it doesn't allow me to do something like this:

git.checkout().setName("$previousCommitId .").call()

The resulting message of it would be the following: org.eclipse.jgit.api.errors.InvalidRefNameException: Branch name 1ff5273b10cdc61386ffe391560b7836da82a412 . is not allowed

Erik B.
  • 87
  • 7
  • `setName` accepts a commit ID (see https://stackoverflow.com/questions/24892748/check-out-specific-revision-from-git-repository-with-jgit). `$previousCommitId .` certainly isn't a valid commit ID. The error message indicates that you pass ` .` (i.e. has plus space plus dot). Use the plain hash and it should work. – Rüdiger Herrmann Aug 28 '21 at 14:15
  • This won't work for me. I need the dot in the end. The difference is that checkout without the dot will result in checking out the revision, whereas the dot updates the files. I actually want to stay on the same revision and only update the files. – Erik B. Aug 28 '21 at 14:30
  • 1
    The dot is part of the pathspec. It seems `git.checkout().setName().setAllPaths(true).call()` is what you are looking for. – Rüdiger Herrmann Aug 28 '21 at 22:35
  • Sadly setAllPaths and setName are mutually exclusive. So I can only checkout (update) everything but not just the single revision. – Erik B. Aug 31 '21 at 09:39

1 Answers1

0

Thanks to Rüdiger Herrman I got closer to the solution. He was already pretty close. Since setName and setAllPaths are mutaly exclusive the only option to reach the goal seems to be:

    git.checkout().setStartPoint(commitHash).setAllPaths(true).call();
Erik B.
  • 87
  • 7