我正在使用 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命令。
非常感谢您的帮助。