Moved folder into submodule, now getting "Untracked files would be overwritten" message
Asked Answered
S

2

26

I work on a team on a large repo. Recently we decided to move one of the folders into its own submodule

-- aaa
     -- .git
     --  bbb
     --  ccc
     --  www      # this folder is going into its own repo.

I followed the instructions to filter out the www folder into its own repo listed here: Detach (move) subdirectory into separate Git repository. I moved the www folder out of the aaa repo.

I removed the directory from the master branch by running these commands:

 $ cd aaa
 $ git checkout master
 $ git rm -rf www
 $ git commit -m "remove the www/ folder from the aaa repo."

So now on master, the tree looks like this:

 -- aaa
     -- .git
     --  bbb
     --  ccc

I'd like to add www as a submodule by running:

$ cd aaa
$ git checkout master
$ git submodule add [email protected]: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.

That works fine on master. However, any time I try to switch to another branch, I get the following error:

$ 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

How can I remove the www folder from all the branches in the aaa repo? There are about 100 branches, so doing this manually would be a hassle.

I'm not worried about keeping any outstanding changes that exist in www folders of older branches.

Stator answered 15/2, 2012 at 18:25 Comment(0)
A
38

Just use git checkout -f to swap branches, then remove them like you normally would and merge in master to get your submodule introduction.

Aiglet answered 15/2, 2012 at 18:28 Comment(3)
Note that if you do a back-and-forth between branches, and the paths have overlapping file names, these files get deleted instead of being reset to the original content.Jabot
Can also happen in the reverse situation where the submodule was introduced on a branch, but not merged to master yet. In which case you just need to git checkout -f, without removing anything if you're moving to such a branch.Belostok
Better yet, use git checkout -f --recurse-submodulesCindy
G
-1

Since you have deleted the path only on working branch. on all other branches the path is available. So your submodule will cause conflict.

Grappling answered 6/5, 2020 at 13:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.