一、版本的回滚
已经push上远程库的提交之后,想反悔之前的提交,回到某次提交的时候,怎么进行版本回滚呢?
使用git图形工具不太好进行操作,直接用命令行
在git的项目下面的终端执行
git reset --hard 80ef71a567
执行日志如下:
HEAD is now at 80ef71a 创建状态码常量,公共返回结果函数,创建业务异常类和业务异常处理函数
-git reset –soft 不会改变stage区,仅仅将commit回退到了指定的提交
git reset –mixed 不回改变工作区,但是会用指定的commit覆盖stage 区,之前所有暂存的内容都变为为暂存的状态
git reset –hard 使用指定的commit的内容覆盖stage区和工作区。
所以现在看本地的项目代码已经撤回到指定回滚版本的样子了。
然后远程还是没有回滚到指定版本,这时候需要将本地的变化push到远程仓库。
终端执行
git push origin master
然后发现提示本地版本落后于远端的版本
git push origin master
Username for 'http://oa.zyqwt.com': lifangxiu
Password for 'http://lifangxiu@oa.zyqwt.com':
To http://oa.zyqwt.com/wanzexi/oa_rebuild.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'http://oa.zyqwt.com/wanzexi/oa_rebuild.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
为了覆盖掉远端的版本信息,使远端的仓库也回退到相应的版本,需要加上参数–force
git push origin master --force
执行日志
Username for 'http://oa.zyqwt.com': lifangxiu
Password for 'http://lifangxiu@oa.zyqwt.com':
Total 0 (delta 0), reused 0 (delta 0)
To http://oa.zyqwt.com/wanzexi/oa_rebuild.git
+ 12587c8...80ef71a master -> master (forced update)
此时去看远程仓库已经回滚到相应的版本了。
二、没联网时的报错
报错信息如下:
$ git clone http://oa.zyqwt.com/wanzexi/big_data.git
Cloning into 'big_data'...
fatal: unable to access 'http://oa.zyqwt.com/wanzexi/big_data.git/': Could not resolve host: oa.zyqwt.com
这个问题的主要原因是我的网络没有通,导致无法访问主机oa.zyqwt.com
所以只要配置好网络就好了,之前老是以为自己没有仓库权限。