libgit2sharp - Git - 无法推送非快进引用

Pao*_*o B 2 c# git libgit2 libgit2sharp

libgit2sharp生成文件后,我正在使用它们将文件推送到存储库。

using (var repo = new Repository(RepositoryPath))
{
    // Stage the file
    Commands.Stage(repo, "*");

    // Create the committer's signature and commit
    Signature author = new Signature("translator", "example.com", DateTime.Now);
    Signature committer = author;

    // Commit to the repository
    Commit commit = repo.Commit($"Resx files updated {DateTime.Now}", author, committer);

    Remote remote = repo.Network.Remotes["origin"];
    var options = new PushOptions
    {
        CredentialsProvider = (_url, _user, _cred) =>
           new UsernamePasswordCredentials
           {
               Username = _settings.GitUserName,
               Password = _settings.GitPassword
           }
     };
     repo.Network.Push(remote, @"refs/heads/master", options);
 } 
Run Code Online (Sandbox Code Playgroud)

这已经有一段时间了,并且没有问题地推送到存储库,但是我现在收到某些文件的以下错误消息,并且没有发生任何文件的推送。

错误消息(来自服务器日志):

Message: cannot push non-fastforwardable reference
StackTrace:  at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_remote_push(RemoteHandle remote, IEnumerable`1 refSpecs, GitPushOptions opts)
   at LibGit2Sharp.Network.Push(Remote remote, IEnumerable`1 pushRefSpecs, PushOptions pushOptions)
   at LibGit2Sharp.Network.Push(Remote remote, String pushRefSpec, PushOptions pushOptions)
   at Westwind.Globalization.Core.Utilities.DbResXConverter.SyncToGit(String resourceSet)
Run Code Online (Sandbox Code Playgroud)

我搜索了错误,但找不到涵盖此内容的任何内容?此外,由于此存储库位于 Azure Web 服务器上,因此我假设我将通过 libgit2sharp C# 代码运行任何 Git 命令,因为我没有运行命令行 Git 命令的权限。

对此的任何帮助表示赞赏。

Edw*_*son 5

如果您的更改不能从远程分支快速转发,则意味着其他人已更新存储库的分支。您需要从远程获取,与远程的分支合并,然后才能推送。

或者,您可以通过在 refspec 前面加上前缀+(例如,+refs/heads/master)来强制推送。