Doing a "git_revert()"is resetting the files marked with the command "git update-index --skip-worktree"

Viewed 71
//code
void RevertTest()
{
  git_object *head_commit_obj = NULL;
  int error = git_revparse_single(&head_commit_obj, repo, "HEAD~1");

  if (error < 0)
  {
    return;
  }

  git_commit *head_commit = (git_commit *)head_commit_obj;

  git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
  opts.checkout_strategy = GIT_CHECKOUT_SAFE;

  int reset_result = git_reset(repo, (git_object *)(head_commit_obj), GIT_RESET_HARD, &opts);

  if (reset_result < 0) 
  {
    return;
  }

}

My problem operated steps:

  1. Create a new project and add it to git for version control

  2. Use git update-index --skip-worktree to exclude *.doc

  3. Use git ls-files -v. | Grep ^ s to view the list of excluded files After calling git_reset provided by libgit2

  4. Use git ls-files -v.grep ^ s to see that the previous mark has been lost.

  5. File pullback using git_reset causes --skip-worktree flag to be lost.

Is there any other way to implement workspace revert without affecting my index data.just as tortoisegit command: "/ command: revert / pathfile:‘ xxx.txt ’"

1 Answers

This is a bug; libgit2 should be respecting the skip-worktree bit in the index, but it is not.

Related