在libgit2sharp https://github.com/libgit2/libgit2sharp/中,您如何检查待处理/未提交的更改?
答案 0 :(得分:13)
以下适用于我:
public bool HasUncommittedChanges
{
get
{
using (var repo = new Repository(repositoryRoot))
{
RepositoryStatus status = repo.RetrieveStatus();
return status.IsDirty;
}
}
}
答案 1 :(得分:4)
您可以使用repository.Diff.Compare()
。
/// <summary>
/// Show changes between the working directory and the index.
/// </summary>
/// <param name = "paths">The list of paths (either files or directories) that should be compared.</param>
/// <returns>A <see cref = "TreeChanges"/> containing the changes between the working directory and the index.</returns>
public virtual TreeChanges Compare(IEnumerable<string> paths = null)
根本不传递任何路径都应该进行所有更改。
答案 2 :(得分:3)
以下代码行将提供该文件的文件名和状态。
foreach (var item in repo1.RetrieveStatus())
{
Console.WriteLine(item.FilePath);
Console.WriteLine(item.State);
}