c# - Repository.Checkout() 不会取消子模块更改

标签 c# libgit2sharp

如果我有这个状态的 repo

On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   App_Data/Submodule
        modified:   file.txt

App_Data/Submodule 是一个 git 子模块,file.txt 只是一个普通文件。

运行 git checkout master --force 将使 repo 处于这种状态

On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   App_Data/Submodule (new commits)

no changes added to commit (use "git add" and/or "git commit -a")

但是使用下面的代码从 LibGit2Sharp 做同样的事情

using (var repo = new LibGit2Sharp.Repository(RepositoryPath))
{
  repo.Checkout("master", new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force });
}

让 repo 处于这种状态

On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   App_Data/Submodule

然而,调用重置按预期工作。

using (var repo = new LibGit2Sharp.Repository(RepositoryPath))
{
    repo.Reset(ResetMode.Hard, "master");
}

LibGit2Sharp 是否会出现这种行为?如果我想反射(reflect)完全相同的 git 行为,我应该自己调用 Reset 吗?

最佳答案

好吧,一年前有人问过这个问题,但我想我会提供一个我找到的解决方案。也许在 LibGit2Sharp 中实现已经改变。

Repository.CheckoutCheckoutModifiers.Force 对我来说无法取消我的子模块更改,但是 Repository.Unstage 在相对子模块的路径。

关于c# - Repository.Checkout() 不会取消子模块更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33030355/

相关文章:

c# - 属性初始化反模式

c# - JSON反序列化,错误: null to value type,如何知道导致错误的确切属性?

c# - 如何从数据库表中提取浮点值并将其分配给 asp.net C# 中的 double 类型变量?

c# - BackgroundWorker 仍然卡住 UI

libgit2 - 我们如何在 Visual Studio 2010 Windows 应用程序中集成 Libgit2 库

c# - 使用具有自己的事务范围的多个 DbContext

git - C# 从 Azure 应用服务将文件推送到 Bitbucket 存储库?

git - 如何将 libgit2sharp 与 ssh 传输协议(protocol)一起使用?

push - Libgit2sharp如何进行镜像推送

git - 我们可以使用 libgit2sharp 从 git 服务器获取特定文件吗?