简体   繁体   English

我做错了吗? 将SVN更改从trunk更改为git分支。 使用merge --squash

[英]Am I doing it wrong? Merging SVN changes from trunk into a git branch. Using merge --squash

We use branches to do our work and keep trunk pristine for the most part. 我们使用分支机构来完成我们的工作,并在大多数情况下保持主干原始状态。 Before merging my changes from my branch into trunk, I want to make sure that I've got the latest changes from svn/trunk into my local branch. 在将我的更改从我的分支合并到主干之前,我想确保从svn / trunk到我的本地分支的最新更改。 It's taken me a bit to figure it out but here's the workflow I've come up with, and I'd like to know if there's a better way of doing it. 我花了一些时间来弄明白,但这是我提出的工作流程,我想知道是否有更好的方法。 (In this example I'm the only one on this branch, so there's no need to git svn rebase for changes to this branch) (在这个例子中,我是这个分支上唯一的一个,所以没有必要git svn rebase来改变这个分支)

git svn fetch
git co -b feature_branch svn/kastner/feature_branch
....work....commit...work...commit
git svn fetch
git merge svn/trunk --squash
git commit -m 'forward merge of svn/trunk'
git svn dcommit

The reasons I'm doing it this way: 我这样做的原因是:

  • git merge without squash will add a git-svn-id pointing to trunk, so dcommit would push there 没有壁球的git merge会添加一个指向trunk的git-svn-id,所以dcommit会推送到那里
  • rebasing to svn/trunk would take this branch totally off the tracks 重新定位到svn / trunk将使这个分支完全偏离轨道

What you're doing here is that you merge changes from svn/trunk to your git feature branch, and then dcommit these changes to svn equivalent of your feature branch. 你在这里做的是你将更改从svn / trunk合并到你的git功能分支,然后将这些更改提交到svn等效的功能分支。 This means you have the branch both in git and svn, which doesn't make too much sense for me if you're working on it alone. 这意味着你有git和svn中的分支,如果你单独使用它,这对我来说没什么意义。

If you haven't yet merged stuff from trunk to this branch the way you describe above, rebasing the branch agains svn/trunk should work just fine. 如果你还没有按照上面描述的方式将主干从trunk转换到这个分支,那么再次重新分配svn / trunk分支应该可以正常工作。 Then you should be able to keep it in git only, and when it's time to merge it in trunk, svn dcommit will push all your changes there, preserving the exact commits. 然后你应该只能将它保存在git中,并且当它在trunk中合并时,svn dcommit会将所有更改推送到那里,保留确切的提交。 (Which should be the best for keeping your history.) (这应该是保持历史最好的。)

To sum up, this is what I'm mostly using: 总而言之,这是我最常用的:

git svn fetch
git checkout -b my_branch svn/trunk
...work...commit...work...commit...
git svn fetch && git rebase svn/trunk
...see if it still works
git svn dcommit # commits all of this to svn trunk

The company where I work also uses Subversion for source control. 我工作的公司也使用Subversion进行源代码管理。 I'm using a different approach: I'm committing very often to my local Git repository but don't want to swamp the Subversion server with my commits as I have several local branches with up to 2000 commits per branch. 我正在使用不同的方法:我经常提交给我的本地Git存储库,但不想使用我的提交来淹没Subversion服务器,因为我有几个本地分支,每个分支最多提交2000个。 Submitting that to Subversion would probably take the better part of a working day. 将其提交给Subversion可能需要一个工作日的大部分时间。 :) :)

# git svn fetch
# git checkout -b some-feature remotes/trunk
# (work, work, work, commit, commit, commit)
# git svn fetch
# git rebase remotes/trunk
# git checkout master
# git merge remotes/trunk    # updates to latest trunk
# git merge --squash some-feature
# git svn dcommit

This way my co-workers see my results as a single (though rather large) commit, the Subversion server does not have too much work with it, and I still have my complete line of development locally. 通过这种方式,我的同事将我的结果视为单个(虽然相当大)的提交,Subversion服务器没有太多的工作,我仍然在本地完成我的完整开发。

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

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