开发者

JGit Java Git Library Unstaging Files

开发者 https://www.devze.com 2023-02-07 00:18 出处:网络
I can\'t get reset to work properly in JGit.Ie. i can add all files to the index, and i can remove/reset/unstage some of them from the index via开发者_如何学JAVA the command below but it doesn\'t work

I can't get reset to work properly in JGit. Ie. i can add all files to the index, and i can remove/reset/unstage some of them from the index via开发者_如何学JAVA the command below but it doesn't work for all files. What is the proper way to unstage files in JGit?

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

Also


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

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


The equivalent of a plain git reset command is

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

0

精彩评论

暂无评论...
验证码 换一张
取 消