Git回退服务器版本及receive.denyDeleteCurrent配置
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