2017-09-30 124 views
0

我克隆了一个存储库,并执行了一些本地更改。如何撤销已提交的子模块命令

然后我做了一个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

如果你犯犯那么,撤消(硬复位)的最后一次提交,然后在你上只有子模块的变化,力推远程(克隆回购)

$ 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 

现在,克隆的回购利用原始(上游)存储库进行更新。

+0

感谢您的建议。这个问题不是最后一次提交,而是之前的许多提交。我想你的建议会失去所有提交的后续内容。有没有办法只更改子模块版本,但保持所有其他提交完好?谢谢。 – Fei

+0

ok,然后,一种方法是恢复提交问题'git还原'。其他方法是仅检查子模块文件夹到特定的提交'git checkout remote/branch - '。 –

+0

谢谢。我使用了'git chdeckout remote/branch - ',它从远程端拉下了最新的变化。 – Fei