简体   繁体   English

Git-Svn dcommit导致分支分裂

[英]Git-Svn dcommit causes branch splitting

I'm having a problem with git-svn dcommits making the git repository lose track of which commits are which. 我遇到了git-svn dcommits的问题,使得git存储库无法跟踪哪些提交。

I try to make sure that the master branch in git always follows trunk in the SVN repository. 我尝试确保git中的master分支始终跟随SVN存储库中的trunk。 So whenever I'm working, I'm on a topic branch. 所以,每当我工作,我都在一个主题分支。 Here's my scenario: 这是我的情景:

Working in a topic branch for a while 在主题分支中工作一段时间

git checkout -b my-topic
git commit -m "blah blah blah"

Then I decide I'd like to merge my branch back in to master 然后我决定将我的分支合并回主人

git checkout master
git svn rebase #get any changes in svn
git rebase master my-topic
git merge my-topic --ff-only

Up until here, everything has gone well. 直到这里,一切都进展顺利。 I now have both master and my-topic up to speed and pointing at the same commit, and the entire history looks like this: 我现在让master和my-topic都达到速度并指向相同的提交,整个历史记录如下所示:

A -- B -- C - master + my-topic

However, when I do 但是,当我这样做的时候

git svn dcommit

I end up with a tree that looks like this (B and C are commits I originally made to the topic): 我最终得到了一个看起来像这样的树(B和C是我最初对该主题做出的提交):

  -- B -- C - my-topic
 /
A -- B -- C - master + remotes/trunk

It seems like during the dcommit process, git pushes the commits up to SVN, then replays them back on top of master. 看起来在dcommit过程中,git将提交推送到SVN,然后在master上重放它们。 The problem I think is that they get different committer information. 我认为问题是他们得到不同的提交者信息。 I'm logging into svn with tortoise plink and an SSH key. 我正在使用tortoise plink和SSH密钥登录svn。

Commits in the git repository that have not been pushed to SVN have committer info as: 在未被推送到SVN的git存储库中提交的提交者信息如下:

Collin Hockey <chockey@xyz.com>

Commits that have been pushed to the svn repository have this though: 已经推送到svn存储库的提交有这个:

chockey <chockey@6206317d-b652-48a9-a948-4036602fc523>

Is there any way I can keep these branches from splitting? 有什么办法可以防止这些分支分裂吗? I can sort of fix it by saying 我可以通过说来解决它

git rebase master my-topic

again, but I feel like that should be unnecessary. 再次,但我觉得这应该是不必要的。 The main problem with this is that once a branch's changes are pushed to SVN, git no longer thinks that branch has been merged anywhere. 这个问题的主要问题是,一旦分支的更改被推送到SVN,git就不再认为分支已被合并到任何地方。 It makes it confusing to delete old branches you no longer need. 删除不再需要的旧分支会让人感到困惑。

The git svn dcommit command works as follows: git svn dcommit命令的工作原理如下:

  1. Find the last commit coming from SVN; 查找来自SVN的最后一次提交; let's call it last-svn 我们把它叫做last-svn
  2. Send the commits in the range last-svn..HEAD to Subversion (discarding the e-mail by the way) last-svn..HEAD范围内的提交发送到Subversion( last-svn..HEAD丢弃电子邮件)
  3. Reset the HEAD to last-svn HEAD重置为last-svn
  4. Update from SVN and create the corresponding commits 从SVN更新并创建相应的提交

In other words, the commits you send to SVN are destroyed and recreated from the update from SVN. 换句话说,您发送到SVN的提交将被销毁并从SVN的更新中重新创建。 This must happen because the commits that come from SVN are different from the ones created with Git: 这必须发生,因为来自SVN的提交与使用Git创建的提交不同:

  • Their description contains a reference to the SVN revision 他们的描述包含对SVN修订的引用
  • Their author e-mail is computed from the SVN username 他们的作者电子邮件是根据SVN用户名计算的

That's why your branch my-topic diverges from master . 这就是为什么你的分支my-topicmaster

You can customize the way git svn dcommit computes the author e-mail from the SVN username with the --authors-file and --authors-prog options. 您可以使用git svn dcommit --authors-file--authors-prog选项自定义git svn dcommit从SVN用户名计算作者电子邮件的方式。

you are right, that git replays the commits again from svn. 你是对的,git再次从svn重播提交。 branches in git are only pointers to commits (or there ids/hashes). git中的分支只是提交(或者有id /哈希)的指针。 the commits from svn will have different hashes, and only the currently checked out branch is updated by git svn dcommit , so your topic branch still points to the old commits 来自svn的提交将具有不同的哈希值,并且只有当前签出的分支由git svn dcommit更新,因此您的主题分支仍指向旧提交

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

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