【问题标题】:LibGit2Sharp CheckoutPaths() to Revert a File without specifying a BranchLibGit2Sharp CheckoutPaths() 在不指定分支的情况下恢复文件
【发布时间】:2017-11-10 23:05:13
【问题描述】:

我想做与git checkout -- file 等效的操作,以丢弃尚未暂存以供提交的文件中的更改。

我已经看到关于how to checkout from a specific commit 的问题,但是我不想指定任何特定的提交或分支。

在以下代码中,commitishOrBranchSpec 的参数似乎是必需的,但不能为 null 或空字符串;有没有可以在这里指定一个值来表示default,类似于上面的git命令行中没有指定任何分支或提交?

using (var repo = new Repository(workingDir))
{
    // $TODO: Figure out what to pass for parameter 1,
    // commitishOrBranchSpec (null and "" don't work)
    repo.CheckoutPaths("", Enumerable.Repeat(filePath, 1));
}

【问题讨论】:

    标签: git git-checkout libgit2 libgit2sharp


    【解决方案1】:

    我已经看到有关如何从特定提交中签出的问题,但是我不想指定任何特定提交或分支。

    您必须指定要结帐的内容。如果你想模拟git checkout -- file,那么你可以简单地使用HEAD 分支。例如:

    repo.checkoutPaths(repo.Head, new string[] { filePath }, checkoutOptions);
    

    【讨论】:

    • 谢谢 - 看起来像 repo.Head.FriendlyName(在这种情况下最终成为字符串 'master'),成功了。
    猜你喜欢
    • 1970-01-01
    • 2017-02-05
    • 2016-06-23
    • 1970-01-01
    • 2011-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多