Git重设-硬并推送到远程存储库 [英] Git reset --hard and push to remote repository
问题描述
我的存储库上有一些错误的提交(在此示例中为D,E和F).
I had a repository that had some bad commits on it (D, E and F for this example).
A-B-C-D-E-F母版和来源/母版
A-B-C-D-E-F master and origin/master
我专门用git reset --hard
修改了本地存储库.我在重设之前进入了一个分支,所以现在我有一个如下所示的仓库:
I've modified the local repository specifically with a git reset --hard
. I took a branch before the reset so now I have a repo that looks like:
A-B-C master
\ D-E-F old_master
A-B-C-D-E-F origin/master
现在我需要这些错误提交的某些部分,所以我从樱桃中挑选了我需要的部分并进行了一些新的提交,因此现在我在本地有了以下内容:
Now I needed some parts of those bad commits so I cherry picked the bits I needed and made some new commits so now I have the following locally:
A-B-C-G-H master
\ D-E-F old_master
现在,我想将此事务状态推送到远程回购.但是,当我尝试执行git push
Git时,会礼貌地给我刷掉:
Now I want to push this state of affairs to the remote repo. However, when I try to do a git push
Git politely gives me the brush off:
$ git push origin +master:master --force
Total 0 (delta 0), reused 0 (delta 0)
error: denying non-fast forward refs/heads/master (you should pull first)
To git@git.example.com:myrepo.git
! [remote rejected] master -> master (non-fast forward)
error: failed to push some refs to 'git@git.example.com:myrepo.git'
如何获取远程存储库以获取本地存储库的当前状态?
How do I get the remote repo to take the current state of the local repo?
推荐答案
如果强制执行推送无济于事("git push --force origin
"或"git push --force origin master
"应该足够),则可能意味着远程服务器已通过 receive.denyNonFastForwards 配置变量拒绝非快进推送(请参阅 git config 联机帮助页以进行描述),或通过update/pre-receive钩子.
If forcing a push doesn't help ("git push --force origin
" or "git push --force origin master
" should be enough), it might mean that the remote server is refusing non fast-forward pushes either via receive.denyNonFastForwards config variable (see git config manpage for description), or via update / pre-receive hook.
对于较旧的Git,您可以通过删除"git push origin :master
"(在分支名称之前查看:")然后重新创建给定分支的"git push origin master
"来解决该限制.
With older Git you can work around that restriction by deleting "git push origin :master
" (see the ':' before branch name) and then re-creating "git push origin master
" given branch.
如果您不能更改此设置,那么唯一的解决方案是代替重写历史记录以创建提交
If you can't change this, then the only solution would be instead of rewriting history to create a commit reverting changes in D-E-F:
A-B-C-D-E-F-[(D-E-F)^-1] master
A-B-C-D-E-F origin/master
这篇关于Git重设-硬并推送到远程存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!