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. Spark 读取HBase数据

    Spark1.6.2 读取 HBase 1.2.3 //hbase-common-1.2.3.jar //hbase-protocol-1.2.3.jar //hbase-server-1.2.3.j ...

  2. js代码检测设备问题:为什么在移动端检测设备的时候会出现pc的页面

    为了在手机上也能正常显示页面,所以为之前写的页面又重写了一遍,专门用来在移动端显示,用js代码检测设备,如果是pc就显示pc的页面,如果是移动就显示移动的页面,但遇到一个问题就是在移动端打开会有一个延 ...

  3. mongodb 索引基础

    一 .索引基础:    MongoDB的索引几乎与传统的关系型数据库一模一样,这其中也包括一些基本的优化技巧.下面是创建索引的命令:    > db.test.ensureIndex({&quo ...

  4. ElasticSearch 单台服务器部署多个节点

    转载:https://www.cnblogs.com/wxw16/p/6160186.html 一般情况下单台服务器只会部署一个ElasticSearch node,但是在学习过程中,很多情况下会需要 ...

  5. 4G手机网络通信是如何被黑客远程劫持的?

    你的4G手机网络通信是如何被黑客远程劫持的?如果您的移动运营商提供LTE(也称为4G网络),则需要小心,因为您的网络通信可能会被远程劫持. 中国一组研究人员发现了无处不在的LTE移动设备标准中的一些关 ...

  6. AGC002[BCDEF]题解

    F是计数于是就做(kan ti jie)了= = B - Box and Ball 模拟一下 每个盒子开一个d表示有的球数 可能存在红球的打个标记 传递一下就行了 #include<cstdio ...

  7. 09.事务管理、整合jpa、整合mybatis

    事务管理 spring-boot-starter-jdbc会自动默认注入DataSourceTransactionManager spring-boot-starter-data-jpa会自动默认注入 ...

  8. 【HDOJ6610】Game(序列带修莫队)

    题意:有n堆石子,第n堆有a[i]个,A先选择一个范围[L,R],B选择一个子区间[l,r],之后照nim游戏的规则进行 现在有询问与操作 每次询问B在给定的[L,R]内有多少种子区间的取法使得A必胜 ...

  9. 2018-2019-2 网络对抗技术 20165206 Exp7 网络欺诈防范

    - 2018-2019-2 网络对抗技术 20165206 Exp7 网络欺诈防范 - 实验任务 (1)简单应用SET工具建立冒名网站 (1分) (2)ettercap DNS spoof (1分) ...

  10. XScreenSaver强大的锁屏工具

    source install:  https://www.jwz.org/xscreensaver/ XScreenSaver     Related articles DPMS Xresources ...