如何获取版本库目录中更改、添加或修改的文件

How to get the files that were changed, added or modified in the repository directory

是否可以从存储库中获取所有 changed/added/removed 文件,然后暂存这些文件?如果是,如何?

我正在做这样的事情:

foreach (string file in Directory.GetFiles("dir/repo", "*", SearchOption.AllDirectories))
{
    repo.Stage(file);
}

然而,这并不令我满意,因为我暂存了所有未跟踪的文件。但我想暂存所有 modified/added/deleted 个文件。

您可以使用 git 命令行工具来获取 changed/added/removed 文件的列表。只需 Google 它,您就会找到大量资源。

看看如何 运行 命令行工具并将输出作为字符串:

How To: Execute command line in C#, get STD OUT results

我想这就是你所需要的。

Is it possible to get all the changed/added/removed files from a repository, and then stage those files? If yes, how?

"Use the wildcard, Luke!";-)

repo.Stage("*") 将模仿 git add --all(来自 git documentation"Update the index not only where the working tree has a file matching but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree." )

请参阅 IndexFixture.csCanMimicGitAddAll() 测试以获得更多见解。