我可以取消填充 Git 子模块吗?

发布于 2024-10-25 11:30:56 字数 94 浏览 2 评论 0原文

一旦我运行,

git update submodule

我可以做些什么来让它回到初始化和更新之前的状态吗?

Once I run

git update submodule

can I do anything to make it go back to the way it was before init and update?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浮萍、无处依 2024-11-01 11:30:56

你说你想回到initupdate之前,这就是子模块仍然存在于.gitmodules中的情况,但它是一个空目录,未在 .git/config 中注册。

假设您的子模块名为 foo/bar,那么您可以执行以下操作:

# Move the submodule out of your repository, just in case you have changes
# in there that you realise afterwards that you'd like to preserve:
mv foo/bar/ ~/backups/old-foo-bar/

# Recreate the submodule directory, but empty this time:
mkdir foo/bar/

# Remove all the config variables associated with that submodule:
git config --remove-section submodule.foo/bar
# Note that the submodule name is *without* the trailing slash

You say that you want to go back to before init and update, which would be the situation where the submodule is still present in .gitmodules, but is an empty directory which isn't registered in .git/config.

Suppose your submodule is called foo/bar, then you could do the following:

# Move the submodule out of your repository, just in case you have changes
# in there that you realise afterwards that you'd like to preserve:
mv foo/bar/ ~/backups/old-foo-bar/

# Recreate the submodule directory, but empty this time:
mkdir foo/bar/

# Remove all the config variables associated with that submodule:
git config --remove-section submodule.foo/bar
# Note that the submodule name is *without* the trailing slash
音栖息无 2024-11-01 11:30:56

尝试(使用 git1.8.3,2013 年 4 月 22 日)a:(

git submodule deinit

请参阅“如何删除 Git 子模块?”)

这将从 .git/config 中删除给定子模块的整个 submodule. 部分

但您可能必须删除该子模块的工作树。

Try (with git1.8.3, April 22d 2013) a:

git submodule deinit

(See "How do I remove a Git submodule?")

This removes the whole submodule.<name> section from .git/config either for the given submodule(s)

You might have to delete the working tree for that submodule though.

雨后彩虹 2024-11-01 11:30:56

如果您的更改已提交,那么您应该能够检查引用日志:

git reflog

找到丢失的更改集后,您可以将其合并回来。

如果您的更改未提交 >,那么它们就无法恢复。

If you changes were commited, then you should be able to check the reflog:

git reflog

Once you find the change set you lost you can merge it back in.

If your changes were not commited, then they cannot be recovered.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文