Add subproject as usual folder to repository
Asked Answered
G

2

7

I noticed that in my directory there were two modules that had been Subprojects of my Git repository. That happened because I moved them all to one Git repo and those modules (directories) had their own .git directory.

When I changed anything in those modules I would not see any changes in my main Git repository. I would see only this:

+Subproject commit e97ff0348e6adc697192ca4e6a367bdaeddcda6b-dirty

etc.

But I don't need that. I only need one Git repository without any subprojects. So I deleted .git directories inside those subprojects. And now I don't see any changes at all on my main repository.

I tried add * and git init. But it just does not see those directories even though it is inside repository. How can I make Git see those directories, so it would track their changes like other modules?

My Git repository looks something like this:

my_project/
 .git
 dir1
 dir2
 dir3 # Let's say this is the one directory that Git does not see. So any changes I make here are not tracked at all.
 ...
 ...

P.S. Those directories that are not tracked are not empty.

Update If I rename that directory, then doing this: git diff

I get this:

diff --git a/dir3 b/dir3
deleted file mode 160000
index e279fc4..0000000
--- a/dir3
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit e279fc481b9706ad79b24281efdbabd55179aee8

If I rename that directory back to original name, then doing git diff, returns nothing or just that there were no changes done.

Gwyngwyneth answered 10/12, 2014 at 14:17 Comment(4)
Try to use git add -A / git add -allGist
Same thing. Does not see changes. When I try commit, it says nothing to commit.Gwyngwyneth
possible duplicate of un-submodule a git submoduleAtiana
Related: here's my solution to this problem in general: https://mcmap.net/q/183491/-git-how-to-make-outer-repository-and-embedded-repository-work-as-common-standalone-repository.Fritter
G
8

After suggestion I looked at this: un-submodule a git submodule

First tried:

git submodule deinit

After this it didn't change the old behavior. But when I did this:

git rm --cached yourSubmodule

Then it removed it as submodule and git started seeing those modules in main repository.

Gwyngwyneth answered 11/12, 2014 at 6:41 Comment(3)
git rm --cached yourSubmodule is misleading, as you're not really removing a git submodule, but rather, just a directory containing another git repo. So, your example really should be git rm --cached path/to/your/subrepo/dir, no? And for your question specifically, since you mention my_project/dir3 is the culprit, it really should just be this, right? git rm --cached dir3.Fritter
What you're really doing with git rm --cached path/to/tracked/file is stopping to track a file. See here: https://mcmap.net/q/11542/-how-do-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore. In the case of a repo within a repo, git, by default, apparently tracks the entire sub-repo's directory as a single file which represents a directory. So, git rm --cached path/to/your/subrepo/dir just stops tracking that single file which represents the subrepo, & now, with its .git folder gone (or just renamed, as I like to do), git will treat it like a normal directory next time you add it.Fritter
Its an old question, so dont remember. But probably yes.Gwyngwyneth
M
0

For Windows

  1. Enable Hidden Files.
  2. Identify the .git folder in the subfolders
  3. Open Git Bash
  4. Navigate to the folder where .git exists
  5. Type the following command rm -rf .git
  6. This will remove the .git folder
  7. Now again stage, commit and push This worked for me
Masteratarms answered 21/3, 2022 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.