如何gitdelete一个分支和一个同名的标签,名称中都带有斜杠?

我有一个 git 分支和一个 git 标签,它们在本地和远程都具有相同的名称和多个斜杠。

我想写一个bash脚本调用git命令删除本地分支和本地标签,然后是远程分支和远程标签。

对于此示例,假设分支/标签名称为: production/2020/12/10

该分支/标签名称是一个假设,可以找到适用于更好命名的分支/标签的解决方案。

任何帮助将不胜感激。

回答

使用完整的refname:

git branch -D refs/heads/production/2020/12/10
git tag -d refs/tags/production/2020/12/10

git push --delete refs/heads/production/2020/12/10 refs/tags/production/2020/12/10

  • That's a good general rule, but note that `git branch` *assumes* a branch name (inserts `refs/heads/` for you, except with `-r` where it inserts `refs/remotes/` instead) and `git tag` *assumes* a tag name. So you don't actually need to do anything special when using `git branch` and `git tag` to delete them.
  • By contrast, when using `git push --delete` or equivalent, it's necessary to use the full name to make sure anything ambiguous resolves the way you want it to. 🙂
  • @matt: the gitrevisions manual page lists a six step process for resolving a refname. Unfortunately nothing seems to mention the fact that `git checkout` doesn't *use* this process, nor the items I mentioned about about `git branch` and `git tag`. Well, more precisely, `git checkout` tries the name as a `refs/heads/<branch>` name first to see if that works. If not, *then* it calls the usual resolve-ref-to-OID functions.

以上是如何gitdelete一个分支和一个同名的标签,名称中都带有斜杠?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>