//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:
Create a new project and add it to git for version control
Use git update-index --skip-worktree to exclude *.doc
Use git ls-files -v. | Grep ^ s to view the list of excluded files After calling git_reset provided by libgit2
Use git ls-files -v.grep ^ s to see that the previous mark has been lost.
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 ’"