使用 svn.pushmergeinfo 进行 merge 的 git-svn 工作流程

标签 git svn merge git-svn mergeinfo

使用 git-svn merge svn 跟踪分支的正确工作流程是什么。我已经阅读了一些关于 git-svn svn.pushmergeinfo 配置键的内容,注意事项是:

来自 http://www.kernel.org/pub/software/scm/git/docs/git-svn.html :

config key: svn.pushmergeinfo

This option will cause git-svn to attempt to automatically populate the svn:mergeinfo property in the SVN repository when possible. Currently, this can only be done when dcommitting non-fast-forward merges where all parents but the first have already been pushed into SVN.

所以我的正常工作流程是:

假设我有一个 SVN 分支 ^/branches/feature_branch

# Ensure git-svn is configured to populate svn:mergeinfo
git config --global svn.pushmergeinfo true   

# Update my local svn remotes state
git svn fetch

# Track a local branch against a remote SVN backed ^/branches/feature_branch 
git checkout -b local_feature_branch remotes/feature_branch

# Modify files and commit to local git repo
git commit -a -m "changes"
# Push changes to SVN branch ^/branches/feature_branch
git svn dcommit

然后将 ^/trunk merge 到我的 local_feature_branch 我假设我做了类似的事情?

# Sync to the latest SVN
git svn fetch
# Rebase "master" which is tracking the remote SVN ^/trunk
git checkout master
git svn rebase

# Checkout the local_feature_branch
git checkout local_feature_branch

# Merge "master" into "local_feature" which is tracking ^/trunk
git merge --squash master
git commit -m "merge master which is tracking SVN ^/trunk"

# Dry run the dcommit to SVN which should include svn:mergeinfo property changes
git svn dcommit --dry-run

# Commit merge to trunk
git svn dcommit 

最佳答案

同时使用merge --squashsvn.pushmergeinfo 没有多大意义。使用 merge --squash,生成的提交将不是 merge 提交,因此后续的 dcommit 不会创建任何 mergeinfo。

我知道 stackoverflow 上的(主要是较旧的)线程建议使用 --squash,但我认为这在很大程度上已成为过去。我一直在使用 git-svn 来管理我们公司的 svn 存储库将近一年,到目前为止,它在以下工作流程中运行良好:

我总是在 merge 之前确保我是最新的,并且为了安全起见,我没有任何本地未同步的提交:

# On local_feature_branch
# Update from SVN
git svn fetch && git svn rebase -l

# push pending commits
git svn dcommit

然后我使用“远程”SVN 分支作为源进行“真正的” merge 。这节省了切换分支和更新,并确保传入分支没有任何本地未同步的提交:

# Create a real, non-forward merge commit
git merge --no-ff svn/trunk

# ... and push it to SVN, including mergeinfo
git svn dcommit

此外,通过这种方式, merge 会正确地记录在本地历史记录中,因此后续 merge 将不必处理先前已解决的冲突。使用 --squash 你会在每次 merge 时重新遇到那些。

但是请注意,当从 local_feature_branch merge 回 trunk 时,mergeinfo 存在一个 Unresolved 问题(即在 svn-speak 中重新整合):Git-SVN with svn.pushmergeinfo: how to avoid self-referencing mergeinfo lines .这在我们的 repo 中很少发生,但到目前为止它没有给我带来任何麻烦。

关于使用 svn.pushmergeinfo 进行 merge 的 git-svn 工作流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11106229/

相关文章:

在 git 子目录中执行 git init

git - 如何使用 git 仓库设置 Dockerfile?

git - SourceTree 中的这些标签是什么意思?

linux - SVN - 通过 VIM 提交 - 恢复失败的提交消息

version-control - 如何在颠覆中将应用程序的免费/付费版本分开

Git pull 覆盖并且不 merge 或确认同一分支(master)上的冲突

git stash - 没有要保存的本地更改但未跟踪的文件

java - 日志文件中的存储库历史记录

mysql - 根据 :user_id and then merge into 1 对 2 个 ActiveRecord 数组进行排序

visual-studio - TFS分支权限