git - 如何丢弃 git 子模块中修改的内容?

标签 git git-submodules

我最近在我的暂存分支中运行了 git 子模块 initupdate 提交。这导致 git 从子模块下载了一堆更改,我不想将这些更改放入暂存阶段并希望完全丢弃。

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   path-to/submodule1 (modified content)
        modified:   path-to/submodule2 (new commits,modified content)
    …


no changes added to commit (use "git add" and/or "git commit -a")

我想放弃所有这些更改,并且不向当前分支添加任何内容。我该怎么做?

最佳答案

由于每个子模块都是其自己的 Git 存储库,因此您可以单独重置每个子模块。

  1. 删除任何未提交的本地更改:进入每个子模块,然后运行 ​​git reset --hard

  2. 通过在顶级运行 git submodule update 来确保每个子模块都位于顶级 Git 存储库所需的提交上。

关于git - 如何丢弃 git 子模块中修改的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70302679/

相关文章:

php - 学说迁移 : How to avoid SQL errors in the postUp step?

git - Gatsby 和 GitHub Pages 的多个分支的用途

git - 是否可以使用 git archive 仅下载在提交/修订中更改的文件

git - 自动将所有子模块添加到仓库

git子模块提交/推/pull

git - 如何在 VSTS 中 CI 构建分支

git - 在 github 中推送提交日期

wordpress - 如何将 WordPress 自动更新与 Git 作为版本控制相结合?

Git 子模块 : specify a specific SHA?

git子模块同步不起作用