git 回滚版本


一、版本的回滚

已经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

所以只要配置好网络就好了,之前老是以为自己没有仓库权限。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值