如何对 TFS 存储库使用 git-tfs 和惯用的 git 分支? [英] How do I use git-tfs and idiomatic git branching against a TFS repository?
问题描述
git 习惯用法是将分支检出到存储库的根目录.签出一个分支会将目录的内容替换为该分支的内容.
The git idiom is to check out branches to the root directory of the repository. Checking out a branch will replace the contents of the directory with the contents of that branch.
TFS 的习惯用法是在存储库的根目录(甚至是 master 或主干分支)下检出 不同目录中的每个分支.签出一个分支会将它放在当前目录旁边的一个新目录中.
The TFS idiom is to check out each branch in a different directory under the root directory of the repository (even the master or trunk branch). Checking out a branch will place it in a new directory next to the current one.
使用 git-tfs,我可以克隆 TFS 存储库或分支到 git 存储库.我想以与 git 分支习惯用法一致的方式在具有多个分支的 TFS 存储库上工作.但我不确定在技术上可行或推荐什么:)
Using git-tfs, I can clone a TFS repository or branch into a git repository. I want to work on a TFS repository with multiple branches in a manner consistent with the git branching idiom. But I'm not sure what's technically possible or recommended :)
如果我从 TFS 中克隆整个存储库
If I clone the whole repository out of TFS
> git tfs clone http://<tfsurl>:8080 $/main
那会给我一个 git master
包含 all TFS 分支作为目录.
That would give me a git master
containing all the TFS branches as directories.
[master]> dir
trunk
feature-logon
feature-search
release-0.0.1
<小时>
为每个 TFS 分支添加一个远程
我不知道我是否可以(或如何)将 git remote 映射到每个 TFS 分支.
Add a Remote Per TFS Branch
I don't know if I can (or how to) map a git remote to each TFS branch.
> git init .
[master]> git tfs clone http://<url> $/main/trunk .
然后
[master]> git checkout -b feature-logon
[feature-logon]> git tfs clone http://<url> $/main/feature-logon .
我知道这在技术上是不正确的,但不玩我不知道有什么更好的(我唯一的 TFS 存储库非常大,实验需要很长时间)
I know this is technically incorrect, but I don't know any better without playing (my only TFS repo is very large, experimenting is taking a long time)
推荐答案
如果使用 git-tfs.这是现在的稳定版本!您首先不是克隆整个存储库,而是克隆主干:
It's now possible to get the TFS branches to be correct Git branches if cloning using git-tfs. This is now in the stable release! You first clone not the entire repository but the trunk :
git tfs clone http://<tfsurl>:8080 $/main/trunk
然后运行 branch --init
,它会在 Git 存储库中创建一个新分支
Then you run branch --init
, which creates a new branch in the Git repository
git tfs branch --init $/MyProject/MyTFSBranch
在你的情况下:
git tfs branch --init $/main/feature-logon
或者在新克隆的存储库上使用 --all
标志来创建 TFS 服务器上存在的所有分支.
Or use the the --all
flag on a fresh cloned repository to create ALL the branches present on the TFS server.
git tfs branch --init --all
您也可以使用标志 --with-branches
直接克隆所有分支:
You could also clone directly with all the branches using flag --with-branches
:
git tfs clone http://<tfsurl>:8080 $/main/trunk --with-branches
这个新命令的文档是这里.随时提供反馈以改进它...
The documentation for this new command is here. Feel free to provide feedback to improve it...
这篇关于如何对 TFS 存储库使用 git-tfs 和惯用的 git 分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!