我在一个大型代码库的团队中工作。最近我们决定将其中一个文件夹移动到它自己的子模块中
-- aaa
-- .git
-- bbb
-- ccc
-- www # this folder is going into its own repo.
我按照说明将 www
文件夹过滤到它自己的存储库中:Detach (move) subdirectory into separate Git repository .我将 www
文件夹移出了 aaa
存储库。
我通过运行这些命令从 master 分支中删除了目录:
$ cd aaa
$ git checkout master
$ git rm -rf www
$ git commit -m "remove the www/ folder from the aaa repo."
所以现在在 master 上,树看起来像这样:
-- aaa
-- .git
-- bbb
-- ccc
我想通过运行将 www
添加为子模块:
$ cd aaa
$ git checkout master
$ git submodule add git@bitbucket.org:kevinburke/www.git www
Cloning into 'www'...
remote: Counting objects: 717, done.
remote: Compressing objects: 100% (392/392), done.
remote: Total 717 (delta 318), reused 711 (delta 317)
Receiving objects: 100% (717/717), 440.52 KiB | 58 KiB/s, done.
Resolving deltas: 100% (318/318), done.
这在 master 上运行良好。但是,每当我尝试切换到另一个分支时,都会出现以下错误:
$ cd aaa
$ git checkout other-old-branch
error: The following untracked working tree files would be overwritten by checkout:
www/1...
www/2...
www/3...
www/4...
Aborting
如何从 aaa
存储库的所有分支中删除 www
文件夹?大约有 100 个分支,因此手动执行此操作会很麻烦。
我不担心保留旧分支的 www
文件夹中存在的任何未完成的更改。
最佳答案
只需使用 git checkout -f
交换分支,然后像往常一样删除它们并 merge 到 master 中以获取子模块介绍。
关于git - 将文件夹移动到子模块中,现在收到 "Untracked files would be overwritten"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9299063/