gpt4 book ai didi

c# - 使用 LibGit2Sharp 暂存未跟踪文件时,Commands.Stage() 不会增加 Staged.Count

转载 作者:行者123 更新时间:2023-12-04 03:08:08 27 4
gpt4 key购买 nike

当我暂存至少一个跟踪文件时,以下 block 起作用。但是当我只暂存未跟踪的文件时,repo.RetrieveStatus().Staged.Count 等于零(我希望它会随着暂存文件的数量增加),因此不满足 if 条件和不要 promise 。

using (var repo = new LibGit2Sharp.Repository(RepoPath))
{
Commands.Stage("*");
Signature author = new Signature(username, email, DateTime.Now);
Signature committer = author;
if (repo.RetrieveStatus().Staged.Any())
{
Commit commit = repo.Commit(CommitMessage, author, committer);
Console.WriteLine(commit.ToString());
}
}

这是一个错误,还是我误用了它?

最佳答案

Staged 集合的定义是:

List of files added to the index, which are already in the current commit with different content

即这些对应于git-status的“changes to be committed”区域中的“modified”,或者git-的M状态status --short.

根据定义,这些不包括暂存的新添加文件。为此,您还需要检查 Added 集合,即:

List of files added to the index, which are not in the current commit

即,这些对应于 git-status 的“changes to be committed”区域中的“new files”,或者 git 的 A status status --short.

但是,您可能还想考虑所有 分阶段更改,我认为这正是您想要做的。您可能希望查看这些集合的状态:

Added: List of files added to the index, which are not in the current commit
Staged: List of files added to the index, which are already in the current commit with different content
Removed: List of files removed from the index but are existent in the current commit
RenamedInIndex: List of files that were renamed and staged (if you requested renames).

目前没有函数可以返回所有分阶段更改的列表,这似乎是一种疏忽(如果您想向 LibGit2Sharp 提交 pull 请求,这很容易纠正!)

关于c# - 使用 LibGit2Sharp 暂存未跟踪文件时,Commands.Stage() 不会增加 Staged.Count,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47269671/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com