繁体   English   中英

如何检测 libgit2sharp 中的未决更改?

[英]How to detect pending changes in libgit2sharp?

在 libgit2sharp https://github.com/libgit2/libgit2sharp/你如何检查挂起/未提交的更改?

以下对我有用:

///DEPRECATED - see comment from @derptastic
public bool HasUncommittedChanges
{
    get
    {
        using (var repo = new Repository(repositoryRoot))
        {
            RepositoryStatus status = repo.RetrieveStatus();
            return status.IsDirty;
        }
    }
}

感谢@Derptastic 提供指向LibGit2Sharp Wiki的链接

以下代码行将提供文件名和该文件的状态。

foreach (var item in repo1.RetrieveStatus())
{
  Console.WriteLine(item.FilePath);
  Console.WriteLine(item.State);
}    

您可以使用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)

根本不传递路径应该给出所有更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM