6

I have two repositories namely A and B. By mistake I cloned repo B inside A on my machine. I removed all the code from the repo B but when I pushed and merged my code from A on origin, it also shows a subproject commit B on Github repo.

I want to remove the subproject commit from my master on origin. Will these steps work?

1. rmdir B (on my local repo A) 2. Pushing my repo A to origin 3. Merging

Hellboy
  • 1,199
  • 2
  • 15
  • 33

2 Answers2

14

Since GitHub displays B as a gray folder within A repo, that means B has been added to A as a submodule.
That gray folder is a gitlink, a special entry in the index.

See "How do I remove a Git submodule?":
Locally, do git submodule deinit asubmodule and git rm B (B without any trailing slash B/).
Then push to GitHub, and B should be gone.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • But I already did rmdir B on my local 'A' repo. And after doing git diff, it shows that : @@ -1 +0,0 @@ -Subproject commit hash_val – Hellboy May 16 '15 at 12:53
  • Did you also do a `git submodule deinit B`? Or at least a `git rm .gitmodules`? And then push `A` to `origin/A`. – VonC May 16 '15 at 12:54
  • No, none of these. I just did cd A/ and rmdir B. – Hellboy May 16 '15 at 12:56
  • 1
    @Hellboy my point is: `B` is declared as a submodule: you need to do some git commands to unregister `B` as a submodule or it will be displayed as such on GitHub. Specifically, you need to remove the gitlink (`git rm B`), and need to unregister it from the submodules list (`git submodule deinit B`). A simple system command like `rmdir` won't be enough to remove B as a submodule. – VonC May 16 '15 at 12:59
5

Assuming you want to remove commit which shown in diff like

-Subproject commit <old commit hash>
+Subproject commit <new commit hash>

go to submodule directory, than

git checkout <old commit hash>

return back to main project:

git add .
git commit --amend --no-edit
git push
Serge S
  • 749
  • 7
  • 3