git - 将文件夹移动到子模块中,现在收到 "Untracked files would be overwritten"消息

标签 git git-submodules

我在一个大型代码库的团队中工作。最近我们决定将其中一个文件夹移动到它自己的子模块中

-- 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/

相关文章:

windows - 在 Windows 上更新 Git Bash 后,仍然显示旧版本

git - 让 Git 不跟踪所有分支

Git 作为部署、开发和备份

javascript - 为什么在 CentOS 上抓包时 `yarn install` 挂起?

git-submodules - VS2022 - 子模块的 Git 更改始终显示更改

git - 排除子模块的子模块

Git子树 merge 策略,可以不 merge 历史吗?

git - gitpython-检查分支是否未与 repo 对象 merge ?

git - 我需要 git 子模块吗?

Git 子模块 - 如何在从主仓库中 pull 时保持子模块更新