Git回退服务器版本及receive.denyDeleteCurrent配置
来源:互联网 发布:淘宝客服接待流程 编辑:程序博客网 时间:2024/05/01 03:08
如果某次修改了某些内容,并且已经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/gitStudyon master⌚ 11:45:37
$ git branch old_master
2.2:push到远程
~/GitHub/sunalong/gitStudyon 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/gitStudyon master⌚ 11:46:52
$ git reset --hard 5391b84
HEAD is now at 5391b84 second add,update the resetdemo
2.4:删除远程的master分支
~/GitHub/sunalong/gitStudyon master⌚ 11:49:29
$ git push origin :master
To /Users/along/GitHub/GitRepository/gitStudy.git
- [deleted] master
2.5:重建master分支
~/GitHub/sunalong/gitStudyon 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/gitStudyon 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/gitStudyon master⌚ 12:25:19
$ head resetdemo
-----create reset files------
2.second add :git reset head ~1Ӧ???ˡ?
3:分支情况:
3.1.删除远程分支之前的分支:
~/GitHub/sunalong/gitStudyon 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/gitStudyon 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/gitStudyon 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/gitStudyon 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/headson master⌚ 11:53:14
$ git receive.denyDeleteCurrent warn
git: 'receive.denyDeleteCurrent' is not a git command. See 'git --help'.
网上许多人抄来抄去,都不验证,将一些正确的配置淹没了,说应该如上配置。
四:解决问题:
4.1.翻墙查询,真正的配置:
~/GitHub/GitRepository/gitStudy.giton 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.giton 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.giton 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/gitStudyon master!⌚20:47:25
$ git reset --help
1 0
- Git回退服务器版本及receive.denyDeleteCurrent配置
- git 回退版本
- Git-版本回退
- git 版本回退
- git回退版本
- git版本回退
- Git版本回退
- git版本回退
- Git版本回退
- git 版本回退
- Git 版本回退
- git版本回退
- git版本回退
- Git回退版本
- git版本回退
- git版本回退
- git版本回退
- git 版本回退
- HDU 5747 BestCoder Round #84 Aaronson (模拟)
- java提高篇之关键字final
- Mini Project #8 - RiceRocks (Asteroids)
- 欢迎使用CSDN-markdown编辑器
- Android开发代号和对应API等级
- Git回退服务器版本及receive.denyDeleteCurrent配置
- 2016 北邮暑期训练3-C题(CodeForces 699BOne Bomb)白痴题
- 精简系统的几个网站
- 欢迎使用CSDN-markdown编辑器
- RecycerView 单独设置每个childView的间隔--使用ItemDecoration
- 串口的流控制
- VMWare清理Linux虚拟机磁盘
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
- python threadpool多线程池的多种玩法