通过 git 删除 svn-Branch?

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

Delete a svn-Branch via git?

gitgit-svn

提问by DerKlops

I'am using git as scm of choice but have to use a svn-repo. I can create a svn-remote-branch like this:

我使用 git 作为 scm 的选择,但必须使用 svn-repo。我可以像这样创建一个 svn-remote-branch:

git svn branch the_branch

But how can i delete the remote branch?

但是如何删除远程分支?

回答by mhagger

Currently, it is not possible to delete an SVN branch using git-svn. But it is easy to delete the branch using SVN, without even having to check it out. So simply type

目前,无法使用 git-svn 删除 SVN 分支。但是使用 SVN 删除分支很容易,甚至不需要检查它。所以只需输入

svn rm $URL/branches/the_branch

Please note that deleting a Subversion branch does not cause it to be deleted from the git-svn repository. (This is intentional, because deleting a Subversion branch does not cause any information loss, whereas deleting a git branch causes its existence to be forgotten following the next git garbage collection.) So if you want the remote SVN branch to be deleted from your git repository, you have to do it manually:

请注意,删除 Subversion 分支不会导致它从 git-svn 存储库中删除。(这是故意的,因为删除一个 Subversion 分支不会导致任何信息丢失,而删除一个 git 分支会导致在下一次 git 垃圾收集之后忘记它的存在。)所以如果你想从你的 git 中删除远程 SVN 分支存储库,您必须手动执行此操作:

git branch -D -r the_branch
rm -rf .git/svn/the_branch

OR
rm -rf .git/svn/refs/remotes/f8745/ (for newer versions)

To delete a git branch that corresponds to a Subversion tag, the commands are slightly different:

要删除对应于 Subversion 标签的 git 分支,命令略有不同:

git branch -D -r tags/the_tag
rm -rf .git/svn/tags/the_tag

回答by Stephen C

This worked well for me, thanks. Not sure if my environment is just different or this was changed in a more recent version of git, but the svn branch dirs were located in .git/svn/refs/remotes/ which was simple enough to find from the original instructions, changing the rm command to:

这对我很有效,谢谢。不确定我的环境是否不同,或者这是否在更新版本的 git 中发生了更改,但是 svn 分支目录位于 .git/svn/refs/remotes/ 中,这很简单,可以从原始说明中找到,更改rm 命令:

rm -rf .git/svn/refs/remotes/the_branch

Not sure about the tags since I don't use those much.

不确定标签,因为我不经常使用这些标签。

回答by alswl

Opps, the top answer was wrote at 2009, now the correct way to delete a remote tag is

哎呀,最佳答案是在 2009 年写的,现在删除远程标签的正确方法是

svn rm svn://dev.in/branches/ios_20130709150855_39721/
git branch -d -r ios_20130709150855_39721

回答by snipsnipsnip

As of 2017, we still don't have git svn branch --delete. (-doption is there but it is for mystic --destination)

截至 2017 年,我们仍然没有git svn branch --delete. (-d选项在那里,但它是神秘的--destination

As described in other answers, manual steps are:

如其他答案中所述,手动步骤是:

  1. Print commit message: git log -1 $commit
  2. In the commit message, locate git-svn-id: $urlline
  3. Remove SVN branch: svn rm $url
  1. 打印提交消息: git log -1 $commit
  2. 在提交消息中,找到git-svn-id: $url
  3. 删除 SVN 分支: svn rm $url

I made an alias to automate these steps:

我做了一个别名来自动化这些步骤:

[alias]
    svn-rm-branch = "!f() { if git_svn_id=\"$(git log -1 --format=%B \"$@\" | grep -o '^git-svn-id:[^@]*')\" ; then svn rm --editor-cmd=\"$(git var GIT_EDITOR)\" \"$(echo $git_svn_id | cut -d' ' -f 2)\" ; else echo No git-svn-id in the message of the commit \"$(git rev-parse \"$@\")\" 1>&2; fi }; f"