Reputation: 85
Consider my local repository contains more than one file, while doing checkout for a particular commit of a file, other files in the repository got deleted.
I am using following API (git
is the instance of git repository)
git.checkout().setName(commitId).call()
Is this correct way to check out a particular commit of a particular file?
Upvotes: 2
Views: 1145
Reputation: 20985
The JavaDoc of setName()
says
When only checking out paths and not switching branches, use
setStartPoint(}
to specify from which branch or commit to check out files.
And for addPath()
it states:
If this option is set, neither the
setCreateBranch()
norsetName()
option is considered. In other words, these options are exclusive.
Therefore I think you should use
git.checkout().addPath( ... ).setStartPoint( ... ).call();
Upvotes: 2
Reputation: 1324347
Your call reset the index (and can remove files no longer present in the new commit you check out)
You can look for a more precise example in jgit/porcelain/RevertChanges.java
// revert the changes
git.checkout().addPath(fileName).call();
In your case:
git.checkout().setname(commitId).addPath(fileName).call()
Upvotes: 0