如果我有这个状态的 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.Checkout
和 CheckoutModifiers.Force
对我来说无法取消我的子模块更改,但是 Repository.Unstage
在相对子模块的路径。
关于c# - Repository.Checkout() 不会取消子模块更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33030355/