【问题标题】:Updating a Git Submodule With Local Changes使用本地更改更新 Git 子模块
【发布时间】:2022-01-23 10:20:09
【问题描述】:

我的一个项目中有一个 Git 子模块,我正在尝试在我进行了一些更改的本地副本上更新它。我希望遥控器覆盖我的本地更改,但是当我尝试以下命令时,没有任何反应,我仍然看到我的本地更改。

joesan@joesan-S-14-v5:~/Projects/Private/github-docs/joesan-me/themes/hugo-clarity$ git status
HEAD detached at d5800ff
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)
    modified:   exampleSite/config/_default/params.toml

no changes added to commit (use "git add" and/or "git commit -a")
joesan@joesan-S-14-v5:~/Projects/Private/github-docs/joesan-me/themes/hugo-clarity$ 

我在这里做错了什么?

【问题讨论】:

  • git status 表示检查和报告,所以它当然没有改变任何东西。如果您想撤消一个文件,请使用git restore,因为它建议您使用git reset --hard,以非常破坏性地撤消所有内容。

标签: git git-submodules


【解决方案1】:

正如@torek 评论所说,git status 仅向您显示您的 git repo 的当前状态。它不会做任何事情。

当您处于超级回购根目录时,您不能简单地使用git reset --hard。您应该在resetcheckoutrestore 之前将cd 放入子模块。

所以:

cd path/to/submodule
git reset --hard  # or git restore .

如果有很多子模块或者你不想cd进入它,你可以使用:

git submodule foreach git reset --hard

但这会影响超级仓库下的所有子模块,请注意!

【讨论】:

    猜你喜欢
    • 2017-06-21
    • 1970-01-01
    • 2018-10-15
    • 1970-01-01
    • 2012-06-07
    • 2019-07-20
    • 2012-12-20
    • 2019-08-09
    • 2014-02-17
    相关资源
    最近更新 更多