Git-svn:批量删除孤立的远程分支 [英] Git-svn: Bulk removing orphaned remote branches

查看:214
本文介绍了Git-svn:批量删除孤立的远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SVN中的项目我正在处理(通过git-svn)经常创建的分支,然后 - 与trunk集成,然后删除。



现在该项目有大约10个未删除的分支,但在git中,git分支-r显示大约50个。



我可以一次删除这些文件,检查它们是否仍然存在于svn存储库中,但它很慢且乏味。有没有办法将我的git远程分支列表与svn repo同步? 解决方案

这是一个quick-n-dirty我在几分钟内做出的解决方案。它使用了很好的正则表达式模式,这些模式在任何地方都是不可用的。



这个抓取了一个清晰的分支列表。我删除每行开头的格式化空间,现在我忽略了标记:

  git branch -r | sed's | ^ [[:space:]] * ||'| grep -v'^ tags /'> git-branch-list 

我从svn中获取一个类似的分支列表,再次删除格式和后向前-slashes:

  svn ls svn://路径/ to / branch / dir / | sed's | ^ [[:space:]] * ||'| sed's | / $ ||'> svn-branch-list 

我对列表进行比较,找到svn中不存在的行列表中删除diff格式,摆脱trunk分支(这是一个git-svn便利),并将结果保存到一个新列表中:

  diff -u git-branch-list svn-branch-list | grep'^  - '| sed's | ^  -  ||'| grep -v'^ trunk $'| grep -v'^  - '> old-branch-list 

现在我只为git-svn执行标准分支移除程序:

 对于`cat old-branch-list`中的i;做git分支-d -r$ i; rm -rf .git / svn / refs / remotes /$ i;完成

可能有更好的方式来做到这一点,但它可行。欢迎其他人参与并加以改进。


A project in SVN I'm working on (via git-svn) has frequently-created branches that are then --reintegrated with trunk, and then deleted.

Right now the project has about 10 branches that have not been deleted, but in git, git branch -r shows about 50.

I can remove these one at a time, checking whether they still exist in the svn repository but it's slow and tedious. Is there a way to sync my list of git remote branches with the svn repo?

解决方案

This is a quick-n-dirty solution I made in a few minutes. It makes use of nice regex patterns that are not available everywhere.

This grabs a clean list of branches. I remove formatting spaces at the beginning of each line, and I'm ignoring tags for now:

git branch -r | sed 's|^[[:space:]]*||' | grep -v '^tags/' > git-branch-list

I grab a similar list of branches from svn, again removing formatting and trailing forward-slashes:

svn ls svn://path/to/branch/dir/ | sed 's|^[[:space:]]*||' | sed 's|/$||' > svn-branch-list

I diff the lists, find the lines that don't exist in the svn list anymore, remove the diff formatting, get rid of the "trunk" branch (which is a git-svn convenience) and save the results to a new list:

diff -u git-branch-list svn-branch-list | grep '^-' | sed 's|^-||' | grep -v '^trunk$' | grep -v '^--' > old-branch-list

Now I just perform standard branch removal procedures for git-svn:

for i in `cat old-branch-list`; do git branch -d -r "$i"; rm -rf .git/svn/refs/remotes/"$i"; done

There's probably better ways of doing this, but it works. Someone else is welcome to take this and improve on it.

这篇关于Git-svn:批量删除孤立的远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆