gpt4 book ai didi

c# - libgit2sharp - Git - 无法推送不可快速转发的引用

转载 作者:太空狗 更新时间:2023-10-29 14:35:55 26 4
gpt4 key购买 nike

我正在使用 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);
}

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

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

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)

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

对此表示感谢的任何帮助。

最佳答案

如果您的更改不能从远程分支快速转发,那么这意味着其他人已经更新了存储库的分支。您需要从远程获取,与远程的分支 merge ,然后您可以推送。

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

关于c# - libgit2sharp - Git - 无法推送不可快速转发的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47294514/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com