假设我的项目布局如下:
MyProject/
├── Examples
│ ├── ExamplesA
│ ├── ExamplesB
│ └── ExamplesC
└── TheLibrary
所以我开发了这个非常棒的库以及一些我希望与库一起分发的用法示例。
问题是,库和那个库必须单独检入TFS存储库。与此同时,我的老板让我保留项目的副本,以便以后可以使用。
当然,MyProject
目录是Git存储库。我正在考虑分支一个目录(即MyProject/TheLibrary
),但是如何使用Git呢?我读过关于git-subtree
的内容,但我担心我会在无尽的pull
和push
es的丛林中丢失。有人可以帮我吗?
理想情况下,我希望有两个分支:master
包含整个项目,tfs
包含MyProject/TheLibrary
文件夹的内容。然后我会创建开发分支并将它们合并到上面的这两个分支中。是否可以使用Git进行类似的事情?
答案 0 :(得分:0)
如果您只想将最新版本的TheLibrary
移动到新分支,您可以这样做(我假设您在分支主机上):
$ git rm -rf Examples
$ git symbolic-ref HEAD refs/heads/tfs
$ git commit -m 'New Branch for TheLibrary'
现在切换回主人并删除TheLibrary
$ git checkout master
$ git rm -rf TheLibrary
$ git commit -m 'TheLibrary moved to branch tfs'
结果将如下所示
Repository View Working Directory View
o-----o-----o-----o MyProject/
^ ├── Examples
| ├── ExamplesA
master ├── ExamplesB
└── ExamplesC
o MyProject/
^ └── TheLibrary
|
tfs
那么会发生什么......
git rm -rf Examples
从工作目录和索引(暂存区域)中删除Examples
及其子目录git symbolic-ref HEAD refs/heads/tfs
让HEAD
参考点指向名为tfs
的新分支git commit -m 'New Branch for TheLibrary'
将索引(现在只包含TheLibrary
)提交为tfs
分支的新提交。git checkout master
切换回主人git rm -rf TheLibrary
从工作目录和索引中删除TheLibrary
。git commit -m 'TheLibrary moved to branch tfs'
对不再包含TheLibrary
的主服务器以及指向新位置的提交消息进行新提交。答案 1 :(得分:0)
好的,我就是这样做的。
我使用
split
TheLibrary
TheLibrary
分支到git subtree split -P TheLibrary -b TheLibrary
分支
TheLibrary
然后我建立了一个单独的分支来维护TFS或其中的git branch TheLibrary-tfs TheLibrary
副本。
clone
然后我只是将TheLibrary-tfs
存储库放入我的TFS工作区并检出commit
分支。
每当我进行特定于TFS的更改时,我只需push
和master
它,它就会保存在TFS存储库之外的本地文件夹中。
每当我需要进行与TFS无关的更改时,我会在push
分支的本地文件夹中执行此操作,然后使用
git subtree push -P TheLibrary . TheLibrary
执行此操作
TheLibrary
以便将更改传播到TheLibrary-tfs
分支。然后我将更改合并到pull
分支。最后,我只需导航到我的TFS工作区,并{{1}}从我的本地文件夹中进行更改。复杂,但有效,似乎正是我所需要的。