64

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 svn branch the_branch

But how can i delete the remote branch?

4 Answers 4

88

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

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:

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:

git branch -D -r tags/the_tag
rm -rf .git/svn/tags/the_tag
Sign up to request clarification or add additional context in comments.

9 Comments

As Stephen C speculates in another answer, the exact structure of the tree in .git/svn depends on how you set up your git-svn configuration. That said, for most common configurations, it shouldn't be hard to figure out the right subdirectories to delete.
would not git gc or git svn gc detect and delete the correct files without the user aving to guess?
Ben: the "rm -rf" commands delete git-svn metadata for the branch. This information is not cleaned up by "git gc" or "git svn gc".
Erik, you are mistaken. If a git branch is deleted, then any of the commits on that branch that were never merged to another branch are subject to being garbage-collected and lost irretrievably (after a grace period of two weeks by default). A deleted Subversion branch, on the other hand, is forever retained in the repository's history and can be viewed, checked out, etc. from a Subversion revision prior to the branch's deletion.
If git has a complete history of the repo, and that branch did exist in the repo, what's the deal with remove things inside .git directory? This is totally misleading newcommers to git from svn.
|
7

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:

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

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

3 Comments

That only deletes it from your local view. Anyone else using the SVN repo will still see it.
@phyzome, this was an addendum to the accepted answer from mhagger, which shows how to remove the svn branch. i can't believe you downvoted for that.
Ah, I see that now. This should really be a comment on mhagger's answer, by the way, instead of a top-level answer.
2

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

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

1 Comment

That's no different than the top answer other than you're using -d instead of -D, which is to not force the delete.
0

As of 2017, we still don't have git svn branch --delete. (-d option is there but it is for mystic --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: $url line
  3. Remove SVN branch: 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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.