如何在一个git存储库中管理两个TFS项目?

时间:2014-09-17 08:44:45

标签: git tfs git-subtree git-tfs

我们使用TFS作为主要的源代码控制,我想使用git作为"前端"与git-tfs rcheckin命令一起但我在将我的存储库导入git时遇到问题。

我的TFS中有两个项目

$/ProjectA
$/ProjectB

我想在一个git存储库中管理它们。

如何将这两个克隆到一个git存储库中,以便我可以将更改作为一个TFS更改集提交并推送到两个项目?

我尝试使用git tfs subtree,但不知怎的,我无法弄清楚这个工作流程。我的方法是初始化git repo,如下所示但是我遇到了无法恢复的错误:

> 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

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,但this answer的一部分指出了正确的方向。

> 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:
....

此错误可能来自git diff-index HEAD命令。当我尝试它时,我得到完全相同的信息。

这里的问题是......还没有HEAD。存储库为空。主分支没有提交,因此,没有头。只需添加一个虚拟提交,然后尝试运行git tfs subtree add ...,它就能正常工作。

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

我的本​​地仓库是空的,就像你的情况一样,这个小技巧刚刚使用git-tfs 0.25.0.0(TFS客户端库14.0)解决了git 2.7.1.windows.2上的ambiguous argument 'HEAD'错误/ p>

编辑:哦,并确保在Windows命令提示符中调用所有git tfs命令。至少在我使用的git / gittfs版本中,git-tfs-subtree在从git-bash控制台调用时无法正常工作,它会混淆一些路径和refspec。

答案 1 :(得分:1)

如果你在TFS上使用Git:

最简单的方法是简单地检查每个项目并将文件添加到单个Git存储库。

如果您在TFS上使用TFVC:

没有办法做到这一点。您可以单独克隆每个仓库并独立处理它们。你不能在一个Git仓库中拥有两种不同的分支结构。

如果您使用的TFVC没有分支:

您可以使用GitTF子树功能来创建一个包含来自TFVC的两个独立同步文件夹的Git仓库。

我建议您永久迁移到Git。