C 在git索引中添加了修改过的文件,但该文件未更改为暂存

C 在git索引中添加了修改过的文件,但该文件未更改为暂存,c,git,libgit2,C,Git,Libgit2,我正在尝试向索引中添加一个文件,以使用libgit2创建提交 回购协议和指数如下所示: git_repository *repo; git_index *my_repo_index; git_repository_open(&repo, "."); git_repository_index(&my_repo_index, repo); git_index_add_bypath(my_repo_index,"a.txt"); //all functions are returnin

我正在尝试向索引中添加一个文件,以使用libgit2创建提交

回购协议和指数如下所示:

git_repository *repo;
git_index *my_repo_index;
git_repository_open(&repo, ".");
git_repository_index(&my_repo_index, repo);
git_index_add_bypath(my_repo_index,"a.txt");
//all functions are returning 0, or success.
“a.txt”文件已存在于索引中,是一个修改过的文件

在提交之前,该文件处于“Changes not staged for commit”下,我认为在提交之后,该文件将处于“staged”下,就像我执行“git add a.txt”之后一样,但这并没有发生


我遗漏了什么吗?

对索引的更改不会立即写入磁盘。例如,您可能希望执行许多操作并同时保存它们。要保存索引,请执行以下操作:

git_index_write(my_repo_index);

或者,您可能不希望索引进入磁盘,例如,如果您正在将一些自动生成的文档提交到分支中。