0

I'm trying to reproduce the checkout file operation using nodegit for reverting current changes of a file.

git checkout -- filename.ext

My first attempt was to use checkoutRef function from Repository object, like this:

nodegit.Repository.open(gitRepo)
  .then(function (repo) {
    repo.checkoutRef('filename.ext',{
      checkoutStrategy: nodegit.Checkout.STRATEGY.FORCE
    }).then(function (data) {
      console.log(data);
    });
});
Okura
  • 123
  • 8

2 Answers2

1

Try the following code: ;-)

try {
    const commit = await repository.getBranchCommit("origin/master");
    const tree = await commit.getTree();
    const resCheckout = await Checkout.tree(repository, tree, { checkoutStrategy: Checkout.STRATEGY.FORCE, paths: ["YOUR_FILE_PATH"] });
} catch (err) {
    console.log(err)
}
Siyavash Hamdi
  • 2,764
  • 2
  • 21
  • 32
0

I think Reset.default is what you want.

rcjsuen
  • 873
  • 1
  • 6
  • 12