How to manage two TFS projects in one git repository?

孤者浪人 提交于 2019-12-10 17:08:00

问题


We are using TFS as main source control and I would like to use git as a "frontend" together with git-tfs rcheckin command but I have problems importing my repositories into git.

I have a two projects in my TFS

$/ProjectA
$/ProjectB

and I would like to manage them in one git repository.

How I can clone those two into one git repository so I can commit and push changes to both projects as one TFS changeset?

I tried using git tfs subtree but somehow I cannot figure out workflow with this. My approach was to init git repo like shown below but I got errors I cannot recover from:

> git init
Initialized empty Git repository in c:/somedir/.git/

> git tfs subtree add --prefix=ProjectA  http://tfs_server:8080/tfs/ $/ProjectA
executing subtree add
-> new owning remote default
-> new remote default_subtree/ProjectA
Fetching from TFS remote 'default_subtree/ProjectA'...
C3779 = 7e532464ef6120ac0b19aa3c7651ceae915dc366
C3780 = 16f4636fc53d729767f65213ed047c11d1a707ee
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
error running command: git subtree add --prefix=ProjectA "-m Add 'ProjectA/' from commit '16f4636fc53d729767f65213ed047c11d1a707ee'

git-tfs-id: [http://tfs_server:8080/tfs/];C3780" refs/remotes/tfs/default_subtree/ProjectA
Command exited with error code: 1

回答1:


I had the same problem, but a part of this answer pointed me to the right direction.

> git init
Initialized empty Git repository in c:/somedir/.git/

> git tfs subtree add --prefix=ProjectA  http://tfs_server:8080/tfs/ $/ProjectA
....
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
....

This error probably comes from git diff-index HEAD command. When I try it, I get exactly the same message.

The problem here is that .. there is no HEAD yet. The repository is empty. The master branch has no commits, hence, no head. Just add a dummy commit and then try running git tfs subtree add ... and it will work fine.

git init
touch foo
git add foo
git commit -m "dummy commit to get a HEAD on master"
git tfs subtree add --prefix=AAA tfsurl $/path/to/AAA
git tfs subtree add --prefix=BBB tfsurl $/path/to/different/BBB

My local repo was empty like in your case and this small trick just solved the ambiguous argument 'HEAD' error for me on git 2.7.1.windows.2 using git-tfs 0.25.0.0 (TFS client library 14.0)

EDIT: Ohh, and be sure to invoke all git tfs commands in a Windows Command Prompt. At least in the git/gittfs versions I use, git-tfs-subtree does not work properly when invoked from a git-bash console and it messes up some paths and refspecs.




回答2:


If you are using Git on TFS:

The easiest way to do this is to simply check out each project and add the files to a single Git repository.

If you are using TFVC on TFS:

There is no way to do this. You can clone each repo separately and work on them independently. You cant have two different branching structures in a single Git repo.

If you are using TFVC with no branches:

You can use the GitTF subtree feature to have a single Git repo that contains two independent synched folders from TFVC.

I would recommend that you migrate permanently to Git.



来源:https://stackoverflow.com/questions/25886008/how-to-manage-two-tfs-projects-in-one-git-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!