git 删除并重新创建分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11844581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git delete and recreate branch
提问by webstrap
Abstract: To reproduce the error
摘要:重现错误
- create a branch and check it out
- let someone else delete it and create a new branch with the same name
- now do
git branch -D <branch>
andgit checkout -b <branch> --track origin/<branch>
- on a
git pull
you get! [rejected] <branch> -> origin/<branch> (non-fast-forward)
- 创建一个分支并检查它
- 让其他人删除它并创建一个同名的新分支
- 现在做
git branch -D <branch>
和git checkout -b <branch> --track origin/<branch>
- 在
git pull
你得到! [rejected] <branch> -> origin/<branch> (non-fast-forward)
to fix it, you have to delete the remote tracking information with git branch -d -r origin/<branch>
as well
要解决这个问题,必须先删除与远程跟踪信息git branch -d -r origin/<branch>
,以及
OLD: Someone deleted the develop branch and created it to remove all feature branches and have the master as base again. Then he added some of the feature branches but not some others that made problems.
旧:有人删除了开发分支并创建了它以删除所有功能分支并再次将 master 作为基础。然后他添加了一些功能分支,但没有添加其他一些会产生问题的分支。
I did a git branch -D develop
and git checkout -b develop --track origin/develop
.
我做了一个git branch -D develop
和git checkout -b develop --track origin/develop
。
When i now try git pull
i get a ! [rejected] develop -> origin/develop (non-fast-forward)
当我现在尝试时,git pull
我得到一个! [rejected] develop -> origin/develop (non-fast-forward)
a git remote show origin
shows
一个git remote show origin
节目
Local refs configured for 'git push':
develop pushes to develop (local out of date)
i can now do a git fetch origin develop
and git merge FETCH_HEAD
but then i have some conflicts and he wants to push a lot of things to develop. (maybe the old branch commits?) And with a git reset --hard
i'm back where the git pull shows the rejected message ..
我现在可以做一个git fetch origin develop
,git merge FETCH_HEAD
但后来我有一些冲突,他想推动很多事情的发展。(也许旧分支提交了?)并且git reset --hard
我回到了 git pull 显示被拒绝消息的地方..
How do i checkout the recreated branch best?
我如何最好地检出重新创建的分支?
EDIT: even when i do git branch -D develop
i get with git pull
! [rejected] develop -> origin/develop (non-fast-forward)
and git remote show origin
said everything (up to date)
编辑:即使当我做git branch -D develop
我与git pull
! [rejected] develop -> origin/develop (non-fast-forward)
和git remote show origin
所说的一切(最新)
EDIT: i didn't recognized it at first, because the commit message was the same, but after a reset the HEAD is on a sha that the remote does not have, so still on the "old" branch ?
编辑:我一开始没有认出它,因为提交消息是相同的,但是在重置后,HEAD 位于遥控器没有的 sha 上,所以仍然在“旧”分支上?
回答by webstrap
i had to delete the tracking branch as well
我也不得不删除跟踪分支
git branch -d -r origin/develop
回答by kisp
You can not pull because it's an other branch now.
你不能拉,因为它现在是另一个分支。
Maybe you should start from scratch and fetch the remote develop
branch as a new local branch!
也许您应该从头开始,将remote develop
分支作为新的本地分支获取!
git checkout -b new_develop --track origin/develop
After doing this, you can merge or change between branches on your local machine. Compare directory trees and other files.
执行此操作后,您可以在本地计算机上的分支之间合并或更改。比较目录树和其他文件。
If you are done editing, just remove your local develop
branch, and rename the new_develop
to develop
.
如果您完成编辑,只需删除您的本地develop
分支,并将其重命名new_develop
为develop
.