JGit Java Git Unstaging Files Library

I cannot get reset to work correctly in JGit. I.e. I can add all files to the index, and I can remove / reset / disconnect some of them from the index using the command below, but it does not work for all files. What is the proper way to disable files in JGit?

repository.getIndex().remove(getWorkignDirectoryAsFile(), new File(getWorkignDirectoryAsFile(), fileName)); repository.getIndex().write(); 

Also

+4
source share
2 answers

You can remove a file from the index using the JGit ResetCommand class:

 ResetCommand reset = new Git(repository).reset(); reset.setRef(Constants.HEAD); reset.addPath("foo.txt"); reset.call(); 
+4
source

Equivalent to a simple git reset command

 git.reset().setMode(ResetType.MIXED).call(); 

Where git is an instance of org.eclipse.jgit.api.Git and ResetType refers to org.eclipse.jgit.api.ResetCommand.ResetType

+1
source

Source: https://habr.com/ru/post/1337117/


All Articles