Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 220
Kevin Burke Avatar asked Feb 15 '12 18:02

Kevin Burke


People also ask

What is submodule dirty?

Submodules are now regarded as dirty if they have any modified files or untracked files, whereas previously it would only be the case if HEAD in the submodule pointed to the wrong commit.

What are untracked files in git?

Untracked files are files that have been created within your repo's working directory but have not yet been added to the repository's tracking index using the git add command.


1 Answers

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

like image 165
Amber Avatar answered Sep 25 '22 18:09

Amber