eclipse - 如何使用 JGit 将文件重置为特定提交?

标签 eclipse git jgit

考虑我的本地存储库包含多个文件,在 checkout 文件的特定提交时,存储库中的其他文件被删除。

我正在使用以下API(git是git存储库的实例)

git.checkout().setName(commitId).call()

这是检查特定文件的特定提交的正确方法吗?

最佳答案

setName() 的 JavaDoc 说

When only checking out paths and not switching branches, use setStartPoint(} to specify from which branch or commit to check out files.

对于addPath(),它指出:

If this option is set, neither the setCreateBranch() nor setName() option is considered. In other words, these options are exclusive.

因此我认为你应该使用

git.checkout().addPath( ... ).setStartPoint( ... ).call();

关于eclipse - 如何使用 JGit 将文件重置为特定提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36541809/

相关文章:

java - java 1.8下无法启动eclipse

Eclipse RCP 插件错误 - 无法解析模块

git - 如何从单独的项目中提取 git 子模块?

git - 如何将未更改的文件添加到 git 索引

gitlab - 如何从java api推送到gitlab

java - 在 Maven 构建过程中,我应该如何配置 Eclipse 以针对不同的 Maven 阶段使用不同的环境变量值?

java - 如何将 JES 库导入到 eclipse 中?

git - 迁移到 LFS 后存储库仍然很大

python - 如何使用 pip 从 git 子目录安装?