c# - 有没有办法使用 libgit2sharp 恢复单个文件?

标签 c# git libgit2sharp

我在 c# 中使用 libgit2sharp 来获取 git 工作目录中的修改/删除/添加文件,我已经完成了这个。

但是我想在 libgit2sharp 的帮助下恢复 git 工作目录中本地更改的文件,那么我该怎么做呢?

最佳答案

这是我对未提交文件的撤消更改的实现:

    public void DiscardFileChanges(string filePath)
    {
        var options = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force };
        _repository.CheckoutPaths(_repository.Head.FriendlyName, new[] { filePath }, options);
    }

说明:您必须在带有 --force 标志的当前分支上 checkout 。本类(class)将您的文件重置为提交版本。

请注意,当您的文件状态为“已添加”时,您必须手动删除此文件。

关于c# - 有没有办法使用 libgit2sharp 恢复单个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43776491/

相关文章:

c# - StreamReader 和 TextReader

github repo 中的 Git 子模块

c# - LibGit2Sharp 和身份验证 UI

git - 使用 VS 2015 Update 3 (TFS 2015 Update 3) 克隆远程存储库时遇到错误

c# - 加密包含 unicode 的字符串会导致无法识别的字符

c# - "button_click"没有重载匹配委托(delegate) 'System.EventHandler'

c# - WinForms DataGridView 抛出 IndexOutOfRangeException

git - 在没有分支的情况下推送 git commit

git - git 统计数据是什么意思?

c# - GIT 智能 HTTP 协议(protocol)的服务端和客户端有哪些细节区别