2017-09-30 99 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