如何更改git中的基本分支?

Sha*_*_42 5 git

问题在图像中描述,因为它在文本中给出了一些错误。

在此处输入图片说明

在此处输入图片说明

Tim*_*sen 9

我不知道为什么您的问题被否决了,因为这是合法的,而且初学者用户在使用 Git 时常犯的错误。

你不小心BR-02从 branch创建了 branch BR-01。一种解决方案是使用正确的基础创建一个分支,然后挑选您BR-02在该正确分支上所做的任何提交。

git checkout BS-00      # switch to the correct branch
git checkout -b BR-03   # create the correct branch using BS-00 as a base
git cherry-pick <SHA-1> # cherry-pick the commit from BR-02
Run Code Online (Sandbox Code Playgroud)

<SHA-1>BR-02您希望保留的分支上提交的哈希值。您可以通过切换到终端BR-02git log从终端输入来找出该值。

请注意,这有效地将您在 branch 上所做的提交合并BR-02到了 branch 中BR-03,因此可能存在冲突。最后,您可以删除坏分支,BR-02因为您不再需要它:

git branch -d BR-02     # delete the wrong branch BR-02 locally
git push origin :BR-02  # delete the wrong branch BR-02 on the remote
Run Code Online (Sandbox Code Playgroud)