【问题标题】:Repository.Checkout() doesn't unstage submodule changesRepository.Checkout() 不会取消暂存子模块更改
【发布时间】:2015-10-09 05:13:42
【问题描述】:

如果我有这个状态的回购

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 });
}

让仓库保持这种状态

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

        modified:   App_Data/Submodule

调用 reset 但按预期工作。

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

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

【问题讨论】:

    标签: c# libgit2sharp


    【解决方案1】:

    嗯,这是一年前提出的,但我想我会提供我找到的解决方案。也许自 LibGit2Sharp 以来实现已经改变。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 2016-07-05
      • 2015-06-19
      • 2018-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多