git 从 github 中删除子项目提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30275691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:00:41  来源:igfitidea点击:

Removing subproject commit from github

gitgithubgit-commitsubproject

提问by Hellboy

I have two repositories namely Aand 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 Bon Github repo.

我有两个存储库,即AB。我错误地在我的机器上的 A 中克隆了 repo B。我从 repo B 中删除了所有代码,但是当我从 A 上推送并合并我的代码时,它还显示了BGithub repo 上的子项目提交。

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

我想从我的 master 上删除子项目提交。这些步骤会奏效吗?

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

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

回答by VonC

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.

由于 GitHub 将 B 显示为 A 存储库中的灰色文件夹,这意味着 B 已作为子模块添加到 A 中。
那个灰色文件夹是一个gitlink,它是索引中的一个特殊条目

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

请参阅“如何删除 Git 子模块?”:在
本地,执行git submodule deinit asubmodulegit rm BB没有任何尾部斜杠B/)。
然后push到GitHub,B应该就没了。

回答by Serge S

Assuming you want to remove commit which shown in diff like

假设您要删除在 diff 中显示的提交,例如

-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