git 删除 Bitbucket 中的分支

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

Delete branches in Bitbucket

gitbitbucketgit-branch

提问by catherine

I've created lots of branches in one of our repositories. Those branches are for testing before it will be pulled to the master. Now I see lots of them on the list and they we will never use it again. How to delete those branches directly to Bitbucket?

我在我们的一个存储库中创建了许多分支。这些分支用于在将其拉到 master 之前进行测试。现在我在名单上看到很多,我们永远不会再使用它。如何将那些分支直接删除到 Bitbucket?

回答by Marcus

If the branches are only local, you can use -dif the branch has been merged, like

如果分支只是本地分支,如果分支已合并,则可以使用-d,例如

git branch -d branch-name

If the branch contains code you never plan on merging, use -Dinstead.

如果分支包含您从不打算合并的代码,请改用-D

If the branch is in the upstream repo (on Bitbucket) you can remove the remote reference by

如果分支位于上游仓库(在 Bitbucket 上),您可以通过以下方式删除远程引用

git push origin :branch-name

Also, if you're on the Bitbucket website, you can remove branches you've pushed by going to the Feature branchestab under Commitson the site. There you'll find an ellipsis icon. Click that, then choose Delete branch. Just be sure you want to drop all the changes there!

此外,如果您在 Bitbucket 网站上,您可以通过转到网站上提交下的功能分支选项卡来删除您推送的分支。在那里你会发现一个省略号图标。单击它,然后选择Delete branch。只要确定你想把所有的改变都放在那里!

enter image description here

在此处输入图片说明

回答by Mital Pritmani

For deleting branch from Bitbucket,

要从 Bitbucket 中删除分支,

  1. Go to Overview (Your repository > branchesin the left sidebar)
  2. Click the number of branches (that should show you the list of branches)
  3. Click on the branch that you want to delete
  4. On top right corner, click the 3 dots (besides Merge button).
  5. There is the option of "Delete Branch" if you have rights.
  1. 转到概览(您的存储库 >左侧边栏中的分支
  2. 单击分支数量(应该会显示分支列表)
  3. 单击要删除的分支
  4. 在右上角,单击 3 个点(除了合并按钮)。
  5. 如果您有权限,可以选择“删除分支”。

回答by Ralf Rafael Frix

In addition to the answer given by @Marcus you can now also delete a remote branch via:

除了@Marcus 给出的答案,您现在还可以通过以下方式删除远程分支:

git push [remote-name] --delete [branch-name] 

回答by Prashant Sharma

in Bitbucketgo to branches in left hand side menu.

Bitbucket 中转到左侧菜单中的分支。

  1. Select your branch you want to delete.
  2. Go to action column, click on three dots (...) and select delete.
  1. 选择要删除的分支。
  2. 转到操作列,单击三个点 (...) 并选择删除。

回答by Ogglas

I could delete most of my branches but one looked like this and I could not delete it:

我可以删除我的大部分分支,但一个看起来像这样,我无法删除它:

enter image description here

在此处输入图片说明

Turned out someone had set Branch permissionsunder Settingsand from there unchecked Allow deleting this branch. Hope this can help someone.

原来有人把Branch permissionsSettings并从那里选中Allow deleting this branch。希望这可以帮助某人。

enter image description here

在此处输入图片说明

Update: Where settings are located from question in comment. Enter the repository that you wan't to edit to get the menu. You might need admin privileges to change this.

更新:评论中问题的设置位于何处。输入您不想编辑的存储库以获取菜单。您可能需要管理员权限才能更改此设置。

enter image description here

在此处输入图片说明

回答by Nanhe Kumar

Step 1 : Login in Bitbucket

第 1 步:登录Bitbucket

Step 2 : Select Your Repository in Repositories list. enter image description here

第 2 步:在存储库列表中选择您的存储库。 在此处输入图片说明

Step 3 : Select branches in left hand side menu. enter image description here

第 3 步:在左侧菜单中选择分支。 在此处输入图片说明

Step4 : Cursor point on branch click on three dots (...) Select Delete (See in Bellow Image) enter image description here

Step4 : 光标在分支上点击三个点 (...) 选择删除(见下图) 在此处输入图片说明

回答by Jyoti Amage

If you are using a pycharm IDE for development and you already have added Git with it. you can directly delete remote branch from pycharm. From toolbar VCS-->Git-->Branches-->Select branch-->and Delete. It will delete it from remote git server.

如果您使用 pycharm IDE 进行开发并且您已经添加了 Git。你可以直接从pycharm中删除远程分支。 从工具栏 VCS-->Git-->Branches-->Select branch--> 和 Delete。它将从远程 git 服务器中删除它。

回答by Dan

I've wrote this small script when the number of branches in my repo exceeded several hundreds. I did not know about the other methods (with CLI) so I decided to automate it with selenium. It simply opens Bitbucket website, goes to Branches, scrolls down the page to the end and clicks on every branch options menu -> clicks Delete button -> clicks Yes. It can be tuned to keep the last N (100 - default) branches and skip branches with specific names (master, develop - default, could be more). If this fits for you, you can try that way.

当我的 repo 中的分支数量超过数百时,我编写了这个小脚本。我不知道其他方法(使用 CLI)所以我决定用 selenium 自动化它。它只是打开 Bitbucket 网站,转到分支,将页面向下滚动到最后,然后单击每个分支选项菜单 -> 单击删除按钮 -> 单击是。可以调整它以保留最后 N 个(100 - 默认)分支并跳过具有特定名称的分支(master、develop - 默认,可能更多)。如果这适合您,您可以尝试这种方式。

https://github.com/globad/remove-old-branches

https://github.com/globad/remove-old-branches

All you need is to clone the repository, download the proper version of Chrome-webdriver, input few constants like URL to your repository and run the script.

您只需要克隆存储库,下载正确版本的 Chrome-webdriver,输入一些常量(如 URL)到存储库并运行脚本。

The code is simple enough to understand. If you have any questions, write comments / create an Issue.

代码简单易懂。如果您有任何问题,请写评论/创建问题。

回答by Ehab Al-Hakawati

Try this command, it will purge all branches that have been merged to the developbranch.

试试这个命令,它会清除所有已经合并到develop分支的分支。

for i in `git branch -r --merged origin/develop| grep origin | grep -v '>' \
   | grep -v master | grep -v develop | sed -E "s|^ *origin/||g"`; \
do \
   git push origin $i --delete; \
done

回答by turkus

If you like fun, then you can just go to the listing page of you branches (for example merged) and just run in the javascript console:

如果你喜欢玩乐,那么你可以去你的分支的列表页面(例如合并)并在 javascript 控制台中运行:

document.querySelectorAll('tr td div a:first-child').forEach(function(item) { fetch('https://bitbucket.org/snippets/new?owner=<yourprofilenick>', {'credentials': 'same-origin'}).then((response) => {return response.text()}).then(function(string) { return /'csrfmiddlewaretoken' value='(.*)'/g.exec(string)[1] }).then(function(csrf) { if (!~item.innerText.indexOf('/')) return; 
 fetch(`https://bitbucket.org/!api/2.0/repositories/<your_organization_path>/refs/branches/${item.innerText}`, {headers: {"x-csrftoken": csrf}, credentials: "same-origin", method: 'DELETE'}).then(() => console.log(`${item.innerText} DELETED!`)) }) })

BEFORE RUN

运行前

  • replace <yourprofilenick>with your BitBucket nick
  • replace <your_organization_path>with your organization path
  • 替换<yourprofilenick>为您的 BitBucket 昵称
  • 替换<your_organization_path>为您的组织路径

HOW IT WORKS

这个怎么运作

First we need a page with with a CSRF token in the page source, so I choose:

首先,我们需要一个页面源代码中带有 CSRF 令牌的页面,所以我选择:

https://bitbucket.org/snippets/new?owner=<yourprofilenick>

https://bitbucket.org/snippets/new?owner=<yourprofilenick>

Then for each branch (in a branch listing) it gets CSRF token and deletes that branch.

然后对于每个分支(在分支列表中),它获取 CSRF 令牌并删除该分支。

BEWARE

谨防

Remeber to prevent sensitive branches before deleting in repo settings.

在 repo 设置中删除之前,请记住防止敏感分支。

It WON'T delete the main branch.

它不会删除主分支。

ADDITIONAL INFO

附加信息

You have to be logged in.

您必须登录。

It deletes only branches visible on that page (so to delete the rest of branches you have to go to the next page).

它仅删除该页面上可见的分支(因此要删除其余的分支,您必须转到下一页)。