git Git删除TFS git存储库中的远程分支

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

Git delete remote branch in TFS git repository

gittfsazure-devops

提问by Eatdoku

we are using git in Team Foundation Service, and we are trying to find a way to delete a remote branch by running the following command.

我们在 Team Foundation Service 中使用 git,我们试图通过运行以下命令找到一种删除远程分支的方法。

git push origin --delete TheBranchName

The remote server keep rejecting with following error

远程服务器不断拒绝以下错误

 ! [remote rejected] TheBranchName (TF401026: The ForcePush permission is required to perform this action.) error: failed to push some refs to 'https://xxx.visualstudio.com/DefaultCollection/_git/Xxxxxx'

any idea how to set correct permission to a user in TFS?

知道如何在 TFS 中为用户设置正确的权限吗?

回答by Ursegor

The security options can be accessed for the repositories at
1. Code->Explorer
2. Select a repo form the Explorer
3. At the details of the repository, you should click to the name of the repository beside the explorer.
4. Select the Manage repositories... menu

可以在
1. 代码->资源管理器中 访问存储库的安全选项
2. 从资源管理器中选择一个
存储库 3. 在存储库的详细信息中,您应该单击资源管理器旁边的存储库名称。
4. 选择管理存储库...菜单

Here you can configure the rights of each contributor groups and individual users for repositories and their branches. "Rewrite and destroy history (force push)" option shound be Allow or Inherited Allow to be able to force push.

您可以在此处配置每个贡献者组和个人用户对存储库及其分支的权限。“重写和销毁历史记录(强制推送)”选项应该是 Allow 或 Inherited Allow 才能强制推送。

回答by MrDustpan

To delete a remote branch you can use:

要删除远程分支,您可以使用:

git push origin :TheBranchName

回答by David Culp

From the git pushman-page:

git push手册页:

-f
--force
    Usually, the command refuses to update a remote ref that is not an ancestor of the
    local ref used to overwrite it. This flag disables the check. This can cause the
    remote repository to lose commits; use it with care.

Looks like the branch you are trying to delete is not an ancestor of the branch you are on -- add this --forceargument and see if it helps.

看起来您尝试删除的分支不是您所在分支的祖先——添加这个--force参数,看看它是否有帮助。

回答by inwenis

I would like to edit Ursegor answerbut I lack the reputation to do so.

我想编辑Ursegor 的答案,但我缺乏这样做的声誉。

In version 14.102.25423.0 (Team Foundation Server 2015 Update 3) the security/permissions options can be accessed for the repositories at:

在版本 14.102.25423.0(Team Foundation Server 2015 更新 3)中,可以在以下位置访问存储库的安全/权限选项:

  1. Code/Explorer
  2. Select a repository from the Explorer
  3. Click the three dots ...beside the repositoy name.
  4. Select Security
  1. Code/Explorer
  2. 从资源管理器中选择一个存储库
  3. 单击...存储库名称旁边的三个点。
  4. 选择 Security

回答by Winner Crespo

In the first answer and the first comment of this linkis answered your question:

在此链接的第一个答案和第一个评论中回答了您的问题:

"Someone has enabled a hook in the remote repo that is prohibiting the delete -- this is usually done so that someone can't push a rebased branch into the repo. (I maintain a fairly large collection of git repositories and they are all configured this way, although not with a hook.)

“有人在远程存储库中启用了一个禁止删除的钩子——这通常是为了让某人无法将重新定位的分支推送到存储库中。(我维护了相当大的 git 存储库集合,它们都已配置这样,虽然没有钩子。)

Look in the hooks/ directory in the remote repository. There will be a script named "update"; this is what's refusing to let you delete the branch."

查看远程存储库中的 hooks/ 目录。会有一个名为“update”的脚本;这就是拒绝让你删除分支的原因。”

回答by Prof Von Lemongargle

I landed on this question searching for a way to delete a branch in VSO. For anyone else who lands here, I have a process which is a little cumbersome, but works. Create a pull request from the branch. Once the pull request is created, abandon it. Once you abandon the request, you are presented with a delete source branch button. Click that to delete the branch.

我登陆了这个问题,寻找一种在 VSO 中删除分支的方法。对于登陆这里的任何其他人,我有一个有点麻烦但有效的过程。从分支创建拉取请求。一旦创建了拉取请求,就放弃它。放弃请求后,您会看到一个删除源分支按钮。单击它以删除分支。

回答by Flea

I just had to open the Git UI tool, open the repo and deleted the branch from there and it worked fine. I couldn't do it from TFS.

我只需要打开 Git UI 工具,打开 repo 并从那里删除分支,它工作正常。我不能从 TFS 做到这一点。