https://blog.csdn.net/sunalongl/article/details/52013435

如果某次修改了某些内容,并且已经commit到本地仓库,
而且已经push到远程仓库了,此此想把本地和远程仓库都回退到某个版本。
上面的git reset只是在本地仓库中回退版本,远程仓库的版本不会变化。
这样,即使本地reset了,但如果再git pull,
那么远程仓库的内容又会和本地之前的内容进行merge.

一:有两种办法解决问题:
1:直接在远程server的仓库目录下,执行git reset --soft 10efa来回退。
注意,在远程不能使用mixed和hard参数。
2:在本地直接把远程的master分支给删除,然后再把reset后的分支push到远程。
2.1:新建old_master分支做备份:
~/GitHub/sunalong/gitStudy on  master 11:45:37
$ git branch old_master
2.2:push到远程
~/GitHub/sunalong/gitStudy on  master 11:46:11
$ git push origin old_master:old_master
Total 0 (delta 0), reused 0 (delta 0)
To /Users/along/GitHub/GitRepository/gitStudy.git
* [new branch] old_master -> old_master
2.3:本地仓库回退到某个版本:
~/GitHub/sunalong/gitStudy on  master 11:46:52
$ git reset --hard 5391b84
HEAD is now at 5391b84 second add,update the resetdemo
2.4:删除远程的master分支
~/GitHub/sunalong/gitStudy on  master 11:49:29
$ git push origin :master
To /Users/along/GitHub/GitRepository/gitStudy.git
- [deleted] master
2.5:重建master分支
~/GitHub/sunalong/gitStudy on  master 12:04:22
$ git push origin master
Total 0 (delta 0), reused 0 (delta 0)
To /Users/along/GitHub/GitRepository/gitStudy.git
* [new branch] master -> master

二:实际操作:
1:日志信息:
1.1.之前日志内容为:
4c08d1c -- [HEAD] sixed commit (26 minutes ago)
538e055 -- [HEAD^] Revert "afater reset head~3" (33 minutes ago)
51d8ff5 -- [HEAD^^] afater reset head~3 (40 minutes ago)
5391b84 -- [HEAD~3] second add,update the resetdemo (52 minutes ago)
77d35ce -- [HEAD~4] Merge branch 'master' of /Users/along/GitHub/GitRepository/gitStudy (54 minutes
03ae3d2 -- [HEAD~5] after git reset HEAD~2 (55 minutes ago)
1.2.之后的日志为:
5391b84 -- [HEAD] second add,update the resetdemo (2 hours ago)
77d35ce -- [HEAD^] Merge branch 'master' of /Users/along/GitHub/GitRepository/gitStudy (2 hours ago
03ae3d2 -- [HEAD^^] after git reset HEAD~2 (2 hours ago)
d1b9696 -- [HEAD~3] create resetdemo file (2 hours ago)

2:源码内容:
2.1.操作之前的内容为:
~/GitHub/sunalong/gitStudy on  master 11:45:31
$ head resetdemo
-----create reset files------
2.second add :git reset head ~1Ӧ???ˡ?
3.sixth add:git reset --hard.
2.2.之后的内容为:
~/GitHub/sunalong/gitStudy on  master 12:25:19
$ head resetdemo
-----create reset files------
2.second add :git reset head ~1Ӧ???ˡ?

3:分支情况:
3.1.删除远程分支之前的分支:
~/GitHub/sunalong/gitStudy on  master 11:48:40
$ git branch -a
encryptBranch
* master
old_master
remotes/origin/HEAD -> origin/master
remotes/origin/encryptBranch
remotes/origin/master
remotes/origin/old_master
3.2.删除远程分支之后的分支:
~/GitHub/sunalong/gitStudy on  master 12:03:44
$ git branch -a
warning: ignoring broken ref refs/remotes/origin/HEAD
encryptBranch
* master
old_master
remotes/origin/encryptBranch
remotes/origin/old_master
3.3.重建分支后:
~/GitHub/sunalong/gitStudy on  master 12:04:57
$ git branch -a
encryptBranch
* master
old_master
remotes/origin/HEAD -> origin/master
remotes/origin/encryptBranch
remotes/origin/master
remotes/origin/old_master

三:删除远程分支遇到问题:
~/GitHub/sunalong/gitStudy on  master 11:49:10
$ git push origin :master
remote: error: By default, deleting the current branch is denied, because the next
remote: error: 'git clone' won't result in any file checked out, causing confusion.
remote: error:
remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: error: current branch, with or without a warning message.
remote: error:
remote: error: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/master
To /Users/along/GitHub/GitRepository/gitStudy.git
! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to '/Users/along/GitHub/GitRepository/gitStudy.git'
错误的操作:
~/GitHub/GitRepository/gitStudy.git/refs/heads on  master 11:53:14
$ git receive.denyDeleteCurrent warn
git: 'receive.denyDeleteCurrent' is not a git command. See 'git --help'.
网上许多人抄来抄去,都不验证,将一些正确的配置淹没了,说应该如上配置。

四:解决问题:
4.1.FQ查询,真正的配置:
~/GitHub/GitRepository/gitStudy.git on  master 12:01:44
$ git config receive.denyDeleteCurrent false
false -- do not deny a ref update that deletes currently checked out
off no -- do not deny a ref update that deletes currently checked out
true yes on -- deny a ref update that deletes currently checked out branch
4.2.配置前:
~/GitHub/GitRepository/gitStudy.git on  master 11:56:55
$ git config --list
credential.helper=osxkeychain
user.email=sunalong@ztgame.com
user.name=sunalong
color.ui=auto
core.autocrlf=input
core.repositoryformatversion=0
core.filemode=true
core.bare=true
core.ignorecase=true
core.precomposeunicode=true
4.3.配置后:
~/GitHub/GitRepository/gitStudy.git on  master 12:03:19
$ git config --list
credential.helper=osxkeychain
user.email=sunalong@ztgame.com
user.name=sunalong
color.ui=auto
core.autocrlf=input
core.repositoryformatversion=0
core.filemode=true
core.bare=true
core.ignorecase=true
core.precomposeunicode=true
receive.denydeletecurrent=false

学习博客: http://www.tech126.com/git-reset/
官方文档:
~/GitHub/sunalong/gitStudy on  master ! 20:47:25
$ git reset --help
————————————————
版权声明:本文为CSDN博主「lasdfdfdsa」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sunalongl/article/details/52013435

Git回退服务器版本及receive.denyDeleteCurrent配置的更多相关文章

  1. redhat6.8服务器版本 yum 源的配置

    阿里云的源地址: http://mirrors.aliyun.com/ 打开后点击帮助: 有如下提示: 不过不能直接使用这个源,因为自己使用的是服务器版本,要修改一个变量,先将源文件下载下来. wge ...

  2. git回退之前版本

    所有没有 commit 的本地改动,都会随着 reset --hard 丢掉,无法恢复. 如果只是想回到 pull 之前当前分支所在的commit位置,则可以.比方说你在 master 分支上,可以用 ...

  3. Git回退到服务器某个版本正确姿势

    背景: Git协作中,成员不可避免地会提交一些错误的版本,由于Git相比SVN引入了本地仓库,操作会相对复杂,以下为姿势分解 找一个源文件RspUtils.java,加上一行注释 //测试回退git服 ...

  4. git回退版本: 回退本地代码版本 + 回退服务器代码版本

    1.回退本地代码版本 借助IDEA开发工具回退版本,点击Version Control ,查看历史版本号: 右击想要回退的版本号,选择Reset Current Branch hear... 选择 H ...

  5. GIT用服务器上的版本强制覆盖掉本地的版本(转)

    以前在机子上使用git下载了linux git版本库上的源代码,由于在阅读源代码的过程中,难免会对本地的文件进行修改,这样就导致本地文件与服务器上的文件版本不一致,我想做的就是用服务器上的版本强制覆盖 ...

  6. IDEA Git回退到指定历史版本

    1.找到要回退的版本号(右击项目--> Git --> Show History -->选中要回退的版本-->Copy Revision Number): 2.打开idea的T ...

  7. 【Git学习笔记】初始化Git仓库和版本回退

    学习地址 http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 什么是版本库呢?版本库又 ...

  8. [原]git的使用(一)---建立本地仓库、add和commit、status和git diff、版本回退使用git reset

    在window下已经安装了git的环境 1.建立本地仓库 mkdir   test     #建立test目录 cd   test        #进入目录 git  init           # ...

  9. Linux操作系统CentOS7.2发行版本的安装与配置(安装是选择服务器类型)

    原文地址:http://1130739.blog.51cto.com/1120739/1738791 由于CentOS 7出来不久,对于这个版本的系统安装与配置的教程较少,今天就索性介绍一下CentO ...

  10. Httpd服务入门知识-Httpd服务常见配置案例之显示服务器版本信息

    Httpd服务入门知识-Httpd服务常见配置案例之显示服务器版本信息 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.httpd配置文件的组成 1>.主要组成 Globa ...

随机推荐

  1. 《最新出炉》系列入门篇-Python+Playwright自动化测试-52- 字符串操作 - 下篇

    1.简介 在日常的自动化测试工作中进行断言的时候,我们可能经常遇到的场景.从一个字符串中找出一组数字或者其中的某些关键字,而不是将这一串字符串作为结果进行断言.这个时候就需要我们对字符串进行操作,宏哥 ...

  2. 03-CSS初步介绍

    01 CSS编写规则 1.1 内联样式 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  3. Linux设备模型:5、device和device driver

    作者:wowo 发布于:2014-4-2 19:28 分类:统一设备模型 http://www.wowotech.net/device_model/device_and_driver.html 前言 ...

  4. 基于 Termux 和 ipv6 把手机打造成公网服务器

    Termux 安装与配置 安装 从这下载: https://f-droid.org/en/packages/com.termux/ 初始化 授权读写手机储存 termux-setup-storage ...

  5. 3568F-翼辉SylixOS国产操作系统演示案例

     

  6. 3568F-系统启动阶段LOGO显示

  7. 详解Web应用安全系列(9)点击劫持

    点击劫持(Clickjacking)漏洞,也被称为界面伪装攻击(UI Redress Attack)或UI覆盖攻击,是一种利用视觉欺骗手段进行的网络攻击方式.这种攻击方式通过技术手段欺骗用户点击他们本 ...

  8. Spring的AOP快速实现通用日志打印

    需求分析 针对VideoService接口实现日志打印 三个核心包 spring-aop:AOP核心功能,例如代理工厂 aspectjweaver:简单理解,支持切入点表达式 aspectjrt:简单 ...

  9. java 类的执行顺序

    java代码 package net.cybclass.sp; public class Test01 { public static void main(String[] args) { new c ...

  10. saltStack自动化工具

    目录 SaltStack自动化工具 核心概念 1. Master 和 Minion 2. State 3. Pillar 4. Grains 5. Modules 6. Runner 7. React ...