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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:20:08  来源:igfitidea点击:

git delete and recreate branch

git

提问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>and git checkout -b <branch> --track origin/<branch>
  • on a git pullyou 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 developand git checkout -b develop --track origin/develop.

我做了一个git branch -D developgit checkout -b develop --track origin/develop

When i now try git pulli get a ! [rejected] develop -> origin/develop (non-fast-forward)

当我现在尝试时,git pull我得到一个! [rejected] develop -> origin/develop (non-fast-forward)

a git remote show originshows

一个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 developand git merge FETCH_HEADbut 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 --hardi'm back where the git pull shows the rejected message ..

我现在可以做一个git fetch origin developgit merge FETCH_HEAD但后来我有一些冲突,他想推动很多事情的发展。(也许旧分支提交了?)并且git reset --hard我回到了 git pull 显示被拒绝消息的地方..

How do i checkout the recreated branch best?

我如何最好地检出重新创建的分支?

EDIT: even when i do git branch -D developi get with git pull! [rejected] develop -> origin/develop (non-fast-forward)and git remote show originsaid 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 developbranch 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 developbranch, and rename the new_developto develop.

如果您完成编辑,只需删除您的本地develop分支,并将其重命名new_developdevelop.