Merge two TFS branches with git tfs

2020-05-26 09:22发布

I'm using git-tfs, and I was wondering if it is possible to merge two TFS branches using git-tfs. I have two branches $/MyCompany/Dev & $/MyCompany/Release-3.3. Release-3.3 originates from the Dev branch. Both are checked out as different git repositories using git tfs.

I'd like to re-incorporate the changes back into the Dev branch. Can this be achieved with git-tfs or will I have to resort to trying to do it using TFS tools?

标签: git tfs git-tfs
3条回答
够拽才男人
2楼-- · 2020-05-26 09:58

Since git-tfs 0.16, you can manage TFS branches (with branch command) so you can now easily init existing branch, create one and merge TFS branches!

https://github.com/git-tfs/git-tfs/blob/master/doc/commands/branch.md#initialize-an-existing-tfs-branch

And since the release 0.19, you can do a git merge of 2 TFS branches and checkin it in TFS (with rcheckin) and it will be checked in as a merge changeset : https://github.com/git-tfs/git-tfs/blob/master/doc/commands/rcheckin.md#checkin-a-merge-changeset

The only limitation (due to TFS) is that all the commits should have been already checked in TFS before doing your merge with git and check it in TFS.

So you can now merge more easily than with 2TFS branches and check them in...

查看更多
一夜七次
3楼-- · 2020-05-26 10:07

I'm not a git-tfs user, but I have done this with git-svn in the past (which I believe has a similar approach). I think your main issue is that you have two repos. If you add both remote branches to the same git repo, you should then be able to do a local merge, do a local commit and then push that commit to TFS.

HTH

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2020-05-26 10:25

I found an awesome, if hacky way of doing this. Git tfs manages it's awareness of areas of TFS using git config. Specifically 3 attributes per remote; url, repository and fetch, for example:

tfs-remote.default.url=http://tfsserver:8080/tfs/collection
tfs-remote.default.repository=$/Product/Branch/Component
tfs-remote.default.fetch=refs/remotes/default/master

You can add another remote by setting these 3 properties again with a different name to default. Eg:

tfs-remote.feature_branch.url=http://tfsserver:8080/tfs/collection
tfs-remote.feature_branch.repository=$/Product/FeatureBranch/Component
tfs-remote.feature_branch.fetch=refs/remotes/default/feature_branch

You may need to issue git tfs bootstrap now.

You can then issue:

git tfs fetch -i feature_branch

Then merge the commits using:

git merge tfs/feature_branch
查看更多
登录 后发表回答