title author date CreateTime categories
git push 错误 hook declined
lindexi
2018-08-10 19:16:52 +0800
2018-2-13 17:23:3 +0800
git

我把仓库上传到 gogs 出现错误,提示如下 remote: hooks/update: line 2: E:/gogs/gogs.exe: No such file or directory
gogs 仓库无法上传,一个原因是移动了gogs,如果把gogs放在移动U盘,插入时,上传经常出现这个问题。

在 push 的提示:

  git push origin master
Counting objects: 32, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (24/24), done.
Writing objects: 100% (32/32), 2.00 MiB | 0 bytes/s, done.
Total 32 (delta 19), reused 13 (delta 7)
remote: hooks/update: line 2: E:/gogs/gogs.exe: No such file or directory
remote: error: hook declined to update refs/heads/master
To http://127.0.0.1:3000/lindexi/gogs.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'http://127.0.0.1:3000/lindexi/gogs.git'

那么如何解决。

可以看到是 hook 炸了,其中 update 文件出现找不到路径。

原因是我把 gogs 从E盘移动到D盘,于是 提交 gogs 仓库出现 remote: hooks/update: line 2: E:/gogs/gogs.exe: No such file or directory

解决方法:

打开 gogs 仓库 gogs ,注意我的gogs仓库之前所在是 E:\gogs\lindexi\gogs.git\ 所以我移动了路径但是里面的路径不会变,打开 update 文件。

可以看到:

  #!/usr/bin/env bash
"E:/gogs/gogs.exe" update $1 $2 $3 --config='E:/gogs/custom/conf/app.ini'

于是我修改 E盘的路径到我现在使用的路径,就好了。

这问题是 update 钩子指向错误的路径。

简单的方法是:

进入控制板,重新生成所有仓库的 Update 钩子。这样就好了。

那么对于备份了 gogs 要恢复,需要如何做?

  1. 修改 custom/conf/app.ini

把 repository 路径修改现在的路径,同样修改日志

  1. 打开 gogs ,进入管理页面

重新生成所有仓库的 Update 钩子

如果对于 gogs 仓库在上传时出现的问题,可以去看gogs故障,也可以联系我:lindexi_gd@163.com

一般有时间我会去看看。

如果对于文章有疑问,欢迎交流。

我写了小程序,可以启动 gogs 判断他是不是移动路径,如果移动,就自动修改,程序很简单。

可以到 http://download.csdn.net/detail/lindexi_gd/9766835 下载。

可以把 gogs 放到任何地方,启动运行 启动.exe 运行可以关闭,gogs继续运行。

代码

    using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using IniParser;
using IniParser.Model; namespace gogs.gocer
{
class Program
{
/// <summary>
/// 自动迁移gogs
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
bool march = ReadCustomAppini();
if (march)
{
Restore();
} string str = System.AppDomain.CurrentDomain.BaseDirectory + "gogs.exe web";
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
p.StartInfo.CreateNoWindow = true;//不显示程序窗口
p.Start();//启动程序 //向cmd窗口发送输入信息
p.StandardInput.WriteLine(str + "&exit"); p.StandardInput.AutoFlush = true;
//p.StandardInput.WriteLine("exit");
//向标准输入写入要执行的命令。这里使用&是批处理命令的符号,表示前面一个命令不管是否执行成功都执行后面(exit)命令,如果不执行exit命令,后面调用ReadToEnd()方法会假死
//同类的符号还有&&和||前者表示必须前一个命令执行成功才会执行后面的命令,后者表示必须前一个命令执行失败才会执行后面的命令 p.OutputDataReceived += (s, e) =>
{
Console.Write(e.Data + "\r\n");
}; p.ErrorDataReceived += (s, e) =>
{
Console.Write(e.Data + "\r\n");
}; //获取cmd窗口的输出信息 while (!p.HasExited)
{
Console.WriteLine(p.StandardOutput.ReadLine());
} string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();//等待程序执行完退出进程
p.Close();
Console.WriteLine(output);
} private static void Restore()
{
string file = System.AppDomain.CurrentDomain.BaseDirectory + "custom\\conf\\app.ini"; var ini = new FileIniDataParser();
IniData customAppini = ini.ReadFile(file); string gogs = System.AppDomain.CurrentDomain.BaseDirectory;
customAppini["repository"]["ROOT"] = gogs.Replace("\\", "/"); gogs = System.AppDomain.CurrentDomain.BaseDirectory + "log";
customAppini["log"]["ROOT_PATH"] = gogs.Replace("\\", "/"); using (StreamWriter stream = new StreamWriter(file))
{
ini.WriteData(stream, customAppini);
} RestoreUpdate(); } private static void RestoreUpdate()
{
var folder = new DirectoryInfo(System.AppDomain.CurrentDomain.BaseDirectory);
var gogs = System.AppDomain.CurrentDomain.BaseDirectory + "gogs.exe";
var gc = System.AppDomain.CurrentDomain.BaseDirectory + "custom\\conf\\app.ini";
gogs = gogs.Replace("\\", "/");
gc = gc.Replace("\\", "/");
foreach (var temp in folder.EnumerateDirectories("*git", SearchOption.AllDirectories))
{
try
{
var file = temp.FullName + "\\hooks" + "\\update"; string str = $"#!/usr/bin/env bash\n\"{gogs}\" update $1 $2 $3 --config='{gc}'"; using (StreamWriter stream = new StreamWriter(file))
{
stream.Write(str);
}
}
catch (Exception)
{ }
}
} private static bool ReadCustomAppini()
{
//当前路径 string file = System.AppDomain.CurrentDomain.BaseDirectory; //获取路径 if (!file.EndsWith("\\"))
{
file += "\\";
}
file += "custom\\conf\\app.ini";
if (!File.Exists(file))
{
return false;
}
var ini = new FileIniDataParser();
IniData customAppini = ini.ReadFile(file);
var gogs = customAppini["repository"]["ROOT"];
gogs = gogs.Replace("/", "\\");
if (!gogs.EndsWith("\\"))
{
gogs += "\\";
} return gogs != AppDomain.CurrentDomain.BaseDirectory;
}
}
}

2018-8-10-git-push-错误-hook-declined-的更多相关文章

  1. git remote: error: hook declined to update

    提交一个项目,push的时候,报错: remote: error: File xxx.rar is MB; this exceeds Git@OSC's file size limit of 100 ...

  2. git push错误解决方案

    错误提示: error: The requested URL returned error: 403 Forbidden while accessing https://nanfei9330@gith ...

  3. github多用户git push错误remote: Permission to user1/z.git denied to user2

    背景:同一台电脑的public key同时添加到了github的两个账户,导致user1的仓库没法正常提交. 解决办法:为两个账户分别配置ssh key,配置~/.ssh/config文件(windo ...

  4. git push 错误,回滚 push操作

    作者:故事我忘了¢个人微信公众号:程序猿的月光宝盒 0.记一次使用git push后,覆盖了同事代码的糗事 前言: ​ 都在WebStorm中操作,Idea或者PyCharm同理 ​ 为了高度还原尴尬 ...

  5. Git push错误non-fast-forward后的冲突解决

    当要push代码到git时,出现提示: error:failed to push some refs to ... Dealing with “non-fast-forward” errorsFrom ...

  6. git push错误,如何回滚

    --> git push Counting objects: 81, done.Delta compression using up to 4 threads.Compressing objec ...

  7. git push解决办法: ! [remote rejected] master -> master (pre-receive hook declined)

    前天准备上传一个project到GitLab上,但是试了很多次都上传不上去,报错如下: ! [remote rejected] master -> master (pre-receive hoo ...

  8. Git push时报错 ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to......

    今天在使用Git回退到之前某个版本的代码时,进行push时出现如下错误: ! [remote rejected] master -> master (pre-receive hook decli ...

  9. Git push提示pre-receive hook declined

    master:local auto@ubuntu:~/src/code/ git push Counting objects: 5, done. Delta compression using up ...

  10. To ssh://xxx.com:8022/test/project.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'ssh://xxx.com:8022/test/project.git'

    To ssh://xxx.com:8022/test/project.git ! [remote rejected] master -> master (pre-receive hook dec ...

随机推荐

  1. 关于javascript提交到java后台空格去不掉ASCII为160的解决办法

    今天正则表达式匹配一个字符串,怎么都不对. 用正则表达式去掉尝试str.replaceAll("\\s*","");  在或者用replaceAll(" ...

  2. SpringBoot 快速支持国际化i18n

    学习目标 快速学会如何在工程中支持国际化语言. 快速查阅 专题阅读:<SpringBoot 布道系列> 源码下载:springboot-locale-i18n — Hey Man,Don' ...

  3. ivew-admin 校验 自定义验证表单多层嵌套

    1.prop=对象 <FormItem label=" prop="shapeDifference.heightSpaceT2"> <Input v-m ...

  4. 浅析HTTP代理原理

    代理服务器是HTTP协议中一个重要的组件,发挥着重要的作用. 关于HTTP代理的文章有很多,本文不再赘述,如果不清楚的可以看一下 HTTP代理的基础知识. 本文主要介绍代理的事例,分析一个真实的案例来 ...

  5. vue之templete模板

    1.templete里要用data里的数据的话,不要加this. 2.按理说Js是写在<script></script>标签体内的.但是Vue的templete模板中对所有的数 ...

  6. Install packages failed: Installing packages: error occurred. ------简单的问题常常会被忽略

    用 pip install 安装了wxpy这个库,但是使用的时候却报错:ImportError: No module named wxpy 我先用 pip list 查看了一下,发现这个库是已经存在的 ...

  7. nyoj 83:迷宫寻宝(二)(计算几何)

    题目链接 枚举所有墙的2n个端点与宝物的位置作为一条线段(墙的端点必定与边界重合), 求出与之相交的最少线段数(判断线段相交时用跨立实验的方法),+1即为结果. #include<bits/st ...

  8. idea将本地项目推送到git远程库

    如何将本地项目推送到github远程仓库? 1. 在github上创建一个仓库,取名mybatis 2. 在idea中将项目交由git管理 注意,文件名会变红了, 说明这些文件在git工作区,但还没规 ...

  9. .NET Core 使用 mongodb

    1.运行环境 开发工具:Visual Studio 2017 JDK版本:.NET Core 2.0 项目管理工具:nuget 2.GITHUB地址 https://github.com/nbfujx ...

  10. 网络体系应用层之万维网、http协议

    1.万维网概述 万维网以客户--服务器方式工作,万维网客户程序就是各式各样的浏览器,万维网文档所驻留的主机则运行服务器程序, 因此这个主机也称为万维网服务器.客户程序向服务器程序发出请求,服务器程序向 ...