简体   繁体   English

本地分支上的git svn dcommit重新创建本地主服务器

[英]git svn dcommit on local branch re-creates local master

Background : 背景

Our team needs to connect to an svn server and work on a particular branch (not the svn trunk). 我们的团队需要连接到svn服务器并在特定分支(而不是svn中继)上工作。 On top, we need to also get the trunk and merge between them. 最重要的是,我们还需要获取主干并在它们之间合并。

I have set up a local git repository connected to our branch ("svn+ssh...project/branches/X"). 我已经建立了连接到我们分支的本地git仓库(“ svn + ssh ... project / branches / X”)。

Then, I have manually added the trunk as a new svn connection ("svn+ssh...project/trunk") (I added a new remote target for the svn trunk, to .git/config) and renamed my branches as follows: 然后,我手动将中继添加为新的svn连接(“ svn + ssh ... project / trunk”)(我将svn中继的新远程目标添加到了.git / config),并按如下方式重命名了我的分支:

master (connected to project/branches/X) was renamed to master-X 主机(连接到项目/分支/ X)已重命名为主机-X

the branch connected to project/trunk was renamed to master-trunk. 连接到项目/主干的分支被重命名为主干。

Question : 问题

When I git svn dcommit on the master-X local branch, a new 'master' branch is created, with the same effect as if I did: 当我在master-X本地分支上git svn dcommit ,将创建一个新的“ master”分支,其效果与我所做的相同:

git svn dcommit
git co master-X -b master

Can I prevent the master branch from being recreated? 我可以防止重新创建master分支吗?

(every time it is created I delete it manually afterwards). (每次创建它后,我都会手动将其删除)。

Edit : 编辑

My .git/config now looks like this: 我的.git / config现在看起来像这样:

# original/default configuration settings skipped for brevity

[svn-remote "svn"]
    url = svn+ssh://...project/branches/X
    fetch = :refs/remotes/git-svn

[svn-remote "svn-trunk"]
    url = svn+ssh://...project/trunk
    fetch = :refs/remotes/git-svn-trunk

The last three lines were added by me. 最后三行是我添加的。

This is old Git behaviour, that has been fixed in recent Git releases. 这是旧的Git行为,在最近的Git版本中已修复。 Anything more recent than Git 1.7.12 will no longer automatically recreate a master branch. 比Git 1.7.12更新的版本将不再自动重新创建master分支。 You can run git --version to get the version of Git you're currently running. 您可以运行git --version来获取当前正在运行的Git的版本。

That's not much use if the version that comes with your operating system is earlier than 1.7.12 (the latest I have easy access to, between my Debian, RHEL and Cygwin systems, is 1.7.9). 如果操作系统随附的版本早于1.7.12(在我的Debian,RHEL和Cygwin系统之间,我可以轻松访问的最新版本是1.7.9),那将没有太大用处。

If you want to, you should be able to make the change yourself, however. 但是,如果需要,您应该可以自己进行更改。 Find the copy of git-svn or git-svn.perl on your system (on mine, it's /usr/lib/git-core/git-svn ), then make the following changes: 在您的系统上找到git-svngit-svn.perl的副本(在我的系统上是/usr/lib/git-core/git-svn ),然后进行以下更改:

  • Below Git::SVN::init_vars() , move the post_fetch_checkout(); Git::SVN::init_vars() ,移动post_fetch_checkout(); line to before the closing brace, so that bit of code looks like so: 到右括号之前的一行,所以这段代码看起来像这样:

     Git::SVN::init_vars(); eval { Git::SVN::verify_remotes_sanity(); $cmd{$cmd}->[0]->(@ARGV); post_fetch_checkout(); }; fatal $@ if $@; exit 0; 
  • In the post_fetch_checkout subroutine… post_fetch_checkout子例程中…

    • Add the following line above the line starting my $gs = : my $gs =开头的行上方添加以下行:

       return if verify_ref('HEAD^0'); 
    • Delete the line that reads like so: 删除如下所示的行:

       return if verify_ref('refs/heads/master^0') 
    • Replace the following lines: 替换以下行:

       my $valid_head = verify_ref('HEAD^0'); command_noisy(qw(update-ref refs/heads/master), $gs->refname); return if ($valid_head || !verify_ref('HEAD^0')); 

      with the following: 具有以下内容:

       command_noisy(qw(update-ref HEAD), $gs->refname); return unless verify_ref('HEAD^0); 

The above changes will apply the patch that changed this behaviour in the Git source code. 以上更改将应用​​在Git源代码中更改此行为的补丁。 You can see that for yourself: the relevant commit is v1.7.11.2-250-ge3bd4dd by Marcin Owsiany. 您可以自己看到:相关的提交是Marcin Owsiany的v1.7.11.2-250- ge3bd4dd。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM