git GitLab 重命名分支并重新开始另一个分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35119034/
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-09 03:53:59  来源:igfitidea点击:

GitLab rename branch and start over on another

gitgitlabatlassian-sourcetreesourcetree

提问by Ray

I just started on a new project and I'm using GitLab with SourceTree. I had created a branch (origin\master) but I did the mistake of using this branch for my development, so I pushed my first few changes to this branch. Now I learned that this branch should actually have the production version and that an origin\develop branch should be used for development.

我刚开始一个新项目,我正在使用 GitLab 和 SourceTree。我已经创建了一个分支(origin\master),但是我错误地将这个分支用于我的开发,所以我将我的前几个更改推送到了这个分支。现在我了解到这个分支实际上应该有生产版本,并且应该使用 origin\develop 分支进行开发。

Is there any way I can rename the master branch to origin\develop and somehow create a new origin\master branch with the original version of the application?

有什么方法可以将 master 分支重命名为 origin\develop 并以某种方式使用应用程序的原始版本创建一个新的 origin\master 分支?

I'm the only developer in the project so it won't affect anyone. If possible, if you can explain how to do it in SourceTree since I don't use the command line git. I'm more familiar with SourceTree.

我是该项目中唯一的开发人员,因此不会影响任何人。如果可能的话,如果你能解释如何在 SourceTree 中做到这一点,因为我不使用命令行 git。我对 SourceTree 比较熟悉。

回答by DominicEU

You could try something like this. Answer modified from this great answer, to suit OP's needs.

你可以尝试这样的事情。从这个很棒的答案修改的答案,以满足 OP 的需求。

git branch -m master develop    # rename master on local
git push origin :master         # delete master on remote
git push origin develop         # create develop on remote
git checkout -b master develop  # create a new local master on top of develop
git push origin master          # create master on remote

回答by Chad Howell

SourceTree instuctions as of version 2.0.20.1

SourceTree 指令自 2.0.20.1 版起

  1. Rename Local branch under "BRANCHES"
    • Right click branch and select "Rename Name of your branch"
  2. Delete remote branch under "REMOTES"
    • Right click branch and select "Delete origin/Name of your branch"
  3. Push your renamed local branch to GitLab
    • Left click you renamed local branch
    • Click the "Push" button on the to ribbon bar
  1. 重命名“BRANCHES”下的本地分支
    • 右键单击分支并选择“重命名分支名称
  2. 删除“REMOTES”下的远程分支
    • 右键单击分支并选择“删除源/分支名称
  3. 将重命名的本地分支推送到 GitLab
    • 左键单击您重命名本地分支
    • 单击功能区栏上的“推送”按钮

回答by Sanjib Sarkar

Easiest way to fix this is to revert the commit. If this was the last commit made, you can fix this by doing the following:

解决此问题的最简单方法是还原提交。如果这是最后一次提交,您可以通过执行以下操作来解决此问题:

$ git revert HEAD

$ git revert HEAD

How to do this in source tree is below:

如何在源树中执行此操作如下:

http://flummox-engineering.blogspot.com/2014/10/how-to-undo-git-commit-in-sourcetree.html

http://flummox-engineering.blogspot.com/2014/10/how-to-undo-git-commit-in-sourcetree.html

Now everything should be back to normal before the push you did to the wrong repository.

现在一切都应该在您推送到错误的存储库之前恢复正常。