假设我的项目布局如下:
MyProject/
├── Examples
│ ├── ExamplesA
│ ├── ExamplesB
│ └── ExamplesC
└── TheLibrary
所以我开发了这个很棒的库和一些我想与库一起分发的使用示例。
问题是,必须将库和单独的库 checkin TFS 存储库。同时,我的老板让我保留一份原样的项目副本,以备后用。
MyProject
directory 是一个 Git 存储库,当然。我正在考虑分支一个目录(即 MyProject/TheLibrary
),但我如何使用 Git 来做到这一点?我读过 git-subtree
,但恐怕我在无尽的丛林中迷路了pull
s 和 push
es。有人可以帮我吗?
理想情况下,我希望有两个分支:master
包含整个项目,以及tfs
与 MyProject/TheLibrary
的内容文件夹。然后我会创建开发分支并将它们 merge 到上面的这两个分支。使用 Git 是否可以做到这一点或类似的事情?
最佳答案
如果你只想将最新版本的 TheLibrary
移动到一个新的分支,你可以这样做(我假设你在分支 master 上):
$ git rm -rf Examples
$ git symbolic-ref HEAD refs/heads/tfs
$ git commit -m 'New Branch for TheLibrary'
现在切换回 master 并删除 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
切换回mastergit rm -rf TheLibrary
从工作目录和索引中删除TheLibrary
。git commit -m 'TheLibrary moved to branch tfs'
在不再包含TheLibrary
的 master 上进行新的提交,并提交一条指向新的提交消息地点。
关于git - 使用 Git 分离要修改的目录作为分支 elsewere,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26844190/