JGit Java Git Library Unstaging Files

一曲冷凌霜 提交于 2019-12-10 17:35:38

问题


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 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


回答1:


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();



回答2:


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



来源:https://stackoverflow.com/questions/4803462/jgit-java-git-library-unstaging-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!