【问题标题】:Change case of folder using libgit2sharp使用 libgit2sharp 更改文件夹大小写
【发布时间】:2020-01-17 05:40:37
【问题描述】:

如何在 libgit2sharp 中重命名目录(在 Windows 下,不区分大小写),如果只是大小写更改?

此代码适用于跨不同目录移动文件:

    File.Move(@"C:\repo\folder1\file.txt", @"C:\repo\folder2\file.txt");
    repo.Index.Remove("folder1/file.txt");
    repo.Index.Add("folder2/file.txt");
    repo.Index.Write();
    var commitResult = repo.Commit(logMessage, author, author);

但是,如果我只是重命名文件夹的大小写,则不起作用:

    Directory.Move(@"C:\repo\folder1\", @"C:\repo\Folder1\");
    repo.Index.Remove("folder1/file.txt");
    repo.Index.Add("Folder1/file.txt");
    repo.Index.Write();
    var commitResult = repo.Commit(logMessage, author, author); // nothing gets written - I get LibGit2Sharp.EmptyCommitException

我还尝试按照this answer 的建议进行 2 次重命名(并在最后提交一次)

我做错了什么还是这是一个 git 限制? 除了进行中间提交之外,还有其他解决方法吗?

PS:我尝试将 repo 更改为 ignorecase=false(Windows 中的默认值为 true),但它也不起作用。

【问题讨论】:

    标签: libgit2 libgit2sharp


    【解决方案1】:

    事实证明,在 git.config 中设置 ignorecase=false 就足够了——但我不得不从一开始就使用它(在第一次提交之前)。

    我只是在我真正删除旧案例并添加新案例的那一刻尝试更改该设置,看起来这还不够 - git 没有检测到更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 2019-11-10
      • 2022-01-11
      • 2013-01-12
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多