现在的位置: 首页 > 综合 > 正文

git仓库配置,版本回滚

2020年02月12日 综合 ⁄ 共 2168字 ⁄ 字号 评论关闭

配置

刚配置好的git仓库服务器,首次提交的时候会报如下错误:

remote: error: refusing to update checked out branch: refs/heads/masterremote: error: By default, updating the current branch in a non-bare repository remote: error: is denied, because it will make the index and work tree inconsistent remote: error: with what you pushed, and will require 'git reset --hard' to matchremote: error: the work tree to HEAD. remote: error:remote: error: You can set 'receive.denyCurrentBranch' configuration variable toremote: error: 'ignore' or 'warn' in the remote repository to allow pushing intoremote: error: its current branch; however, this is not recommended unless youremote: error: arranged to update its work tree to match what you pushed in some remote: error: other way.remote: error: To squelch this message and still keep the default behaviour, set remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To ... ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to

需要配置一下git的接收配置,执行如下命令即可正确提交:

git config receive.denyCurrentBranch ignore

在服务器上需要看到提交上来的文件需要使用命令同时这个命令也可以回退版本

git reset --hard HEAD

回滚版本

首先,Git必须知道当前版本是哪个版本,在Git中,用HEAD表示当前版本,也就是最新的提交3628164...882e1e0(注意我的提交ID和你的肯定不一样),上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100 现在,我们要把当前版本“append GPL”回退到上一个版本“add distributed”,就可以使用git reset命令:

$ git reset --hard HEAD^HEAD is now at ea34578 add distributed

--hard参数有啥意义?这个后面再讲,现在你先放心使用。 看看readme.txt的内容是不是版本add distributed

$ cat readme.txtGit is a distributed version control system.Git is free software.

果然。还可以继续回退到上一个版本wrote a readme file,不过且慢,然我们用git log再看看现在版本库的状态:

$ git logcommit ea34578d5496d7dd233c827ed32a8cd576c5ee85Author: Michael Liao <askxuefeng@gmail.com>Date: Tue Aug 20 14:53:12 2013 +0800 add distributedcommit cb926e7ea50ad11b8f9e909c05226233bf755030Author: Michael Liao <askxuefeng@gmail.com>Date: Mon Aug 19 17:51:55 2013 +0800 wrote a readme file

最新的那个版本append GPL已经看不到了!好比你从21世纪坐时光穿梭机来到了19世纪,想再回去已经回不去了,肿么办?办法其实还是有的,只要上面的命令行窗口还没有被关掉,你就可以顺着往上找啊找啊,找到那个append GPLcommit id3628164...,于是就可以指定回到未来的某个版本:

$ git reset --hard 3628164HEAD is now at 3628164 append GPL

版本号没必要写全,前几位就可以了,Git会自动去找。当然也不能只写前一两位,因为Git可能会找到多个版本号,就无法确定是哪一个了。再小心翼翼地看看readme.txt的内容:

$ cat readme.txtGit is a distributed version control system.Git is free software distributed under the GPL.

果然,我胡汉三又回来了。

以上就上有关git仓库配置,版本回滚的全部内容,学步园全面介绍编程技术、操作系统、数据库、web前端技术等内容。

抱歉!评论已关闭.