如何撤消已提交的子模块命令

时间:2017-09-30 07:10:11

标签: git github git-submodules

我克隆了一个存储库,并执行了一些本地更改。

然后我做了一个git pull origin来从原点获得更新。然后我做一个git push来推送到我的克隆存储库。但是,不推送子模块:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    typechange: third_party/aten (new commits)
    modified:   third_party/cub (new commits)
    modified:   third_party/eigen (new commits)
    modified:   third_party/gloo (new commits)
    modified:   third_party/nccl (new commits)

我不知道我可以使用git submodule update来更新它们。我添加了它们,提交并推送到我的克隆存储库。

这是错误的。我的克隆存储库落后于原点。现在我对原点有一个拉取请求,并且包含了提交。

只是想知道是否有一种简单的方法来撤消它。强制克隆的存储库使用与源相同的版本。

非常感谢!

1 个答案:

答案 0 :(得分:1)

如果您仅提交了上次提交中的子模块更改,则撤消(硬重置)上次提交,然后强制推送到远程(克隆存储库)

$ git reset --hard HEAD~1      # undo the last commit
$ git push -f

撤消子模块更改的替代方法:

  

“这不是最后一次提出这个问题”(在评论中提到)

仅将子模块文件夹签出到未提交文件夹更改的特定commitremote branch

$ git fetch
$ git checkout <remote>/<branch> -- <submodule-folder>

Or,
$ git log     # copy the commit hash want to get back the submodule folder
$ git checkout <commit-hash> -- <submodule-folder>
  

“强制我的克隆存储库使用与原始版本相同的版本。”

在这里,我猜origin = upstream(从你克隆回购的地方)。因此,您可以从upstream提取更改,然后推送到克隆的repo分支。

$ git remote add upstream <upstream repo url> # add a new remote with the original repo url

$ git pull upstream master     # pull the upstream master branch changes into local branch
$ git push                     # update remote branch

现在,克隆的repo将使用原始(上游)存储库进行更新。