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. 【抓包工具之Fiddler】增加IP列;session高亮

    Fiddler 在处理每个session时,脚本文件CustomRules.js中的方法都会运行,该脚本使得你可以隐藏,标识或任意修改负责的session.规则脚本在运行状态下就可以修改并重新编译,不 ...

  2. MySQL学习笔记_时间,多表更新,数据库元数据

    MySQL技术内幕一.MySQL基础知识1.1.显示表中的列SHOW COLUMNS FROM order_info like 'order%'1.2.显示表SHOW TABLES LIKE 'ord ...

  3. nodejs部署配置pm2

    高大上先上部署node方式: 直接通过node app来启动,如果报错了可能直接停在整个运行, supervisor感觉只是拿来用作开发环境的. 目前似乎最常见的线上部署nodejs项目的有forev ...

  4. UiAutomator、UiAutomator2、Bootstrap的关系

    很多同学经过一段时间的学习之后都明白了Appium的基本原理,但是越学习到后面发现出现的很多陌生名词无法弄清楚其具体作用,今天这篇文章的目的就是为了让大家来弄懂三个高频名词:UiAutomator.U ...

  5. 天池平台再升级,打造产业AI知识共享、技术共享平台

    在5月23日的云栖大会·武汉峰会上,天池发布“全球AI开发者计划”,打造一站式人工智能知识共享平台,计划2年内在平台上集聚30万AI工程师.同时,阿里云天池正式升级,成为从产业机会到实施交付一站式解决 ...

  6. Python爬虫之抓图

    从"百度图片(http://image.baidu.com/)"的首页下载图片 # -*- coding: utf-8 -*- import urllib import re im ...

  7. npm 常见错误记录

    1.Module build failed: ReferenceError: Unknown plugin "import" specified in "base&quo ...

  8. 4412 chmod权限

    chmod权限 使用命令"man 2 chmod"学习chmod函数• int chmod(const char *path, mode_t mode);– 参数*path:文件路 ...

  9. 云平台(cloud platforms)

    云平台:允许开发者们或是将写好的程序放在“云”里运行,或是使用“云”里提供的服务,或二者皆是的服务 转向云计算(cloud computing),是业界将要面临的一个重大改变.各种云平台(cloud ...

  10. LOJ 3094 「BJOI2019」删数——角标偏移的线段树

    题目:https://loj.ac/problem/3094 弱化版是 AGC017C . 用线段树维护那个题里的序列即可. 对应关系大概是: 真实值的范围是 [ 1-m , n+m ] :考虑设偏移 ...