Removing subproject commit from github
Asked Answered
G

2

7

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

Glassworker answered 16/5, 2015 at 12:28 Comment(2)
Does it shows B as in https://mcmap.net/q/145376/-what-does-a-grey-icon-in-remote-github-mean?Seraphic
Yes. Exactly the same.Glassworker
S
15

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.

Seraphic answered 16/5, 2015 at 12:50 Comment(4)
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_valGlassworker
Did you also do a git submodule deinit B? Or at least a git rm .gitmodules? And then push A to origin/A.Seraphic
No, none of these. I just did cd A/ and rmdir B.Glassworker
@Glassworker 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.Seraphic
R
8

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
Runin answered 6/4, 2020 at 6:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.