2016-07-06 59 views
1

我們需要回到特定的提交時間。掌握了一些意外的變化。試圖恢復它挖得太深,所以主人處於不良狀態。我們現在想讓主人回到66ada4cc61d62afc。回到版本庫中的特定版本後提交併推送更改?

根據git revert back to certain commit

$ git reset --hard 66ada4cc61d62afc 
HEAD is now at 66ada4c Updated documentation 

然後,試圖將其提交:

$ git add *.h *.cpp 
$ git commit -m "Go back to Commit 66ada4cc61d62afc" 
On branch master 
Your branch is behind 'origin/master' by 16 commits, and can be fast-forwarded. 
    (use "git pull" to update your local branch) 

nothing to commit, working directory clean 

最後:

$ git push 
To https://github.com/weidai11/cryptopp.git 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to 'https://github.com/weidai11/cryptopp.git' 
hint: Updates were rejected because the tip of your current branch is behind 
hint: its remote counterpart. Integrate the remote changes (e.g. 
hint: 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

眼下,一切也正是它,我想是。我不知道Git爲什麼會遇到麻煩,Git在談論什麼。如果Git完成了它被告知的事情,那肯定會很好。但是,唉,Git讓每一個簡單的任務都變得困難,並且會給人帶來不必要的痛苦和痛苦。

如何提交和推送更改?

回答

-2

爲了避免簡單地更換一組錯誤的另一部分解決辦法,我執行以下操作:

git clone https://github.com/weidai11/cryptopp.git cryptopp-old 
git clone https://github.com/weidai11/cryptopp.git cryptopp-new 

cd cryptopp-old 
git checkout 66ada4cc61d62afc 

cd ../cryptopp-new 
cp ../cryptopp-old/*.h ../cryptopp-old/*.cpp . 

git commit -am "Go back to Commit 66ada4cc61d62afc" 
3

git reset將不會恢復您的更改。它會回到較舊的狀態。由於最新的提交已經在遠程,並且您沒有進行任何本地更改,您將無法推送。使用git revert <hash>git revert <hash1>..<hash2>。這將創建一個新的提交,恢復您指定提交的更改。然後推動代碼。

+0

'git的revert'被審判,但它成功地撤銷之前'66ada4cc61d62afc'變化。我認爲這是因爲意外推動的公關反對以前的圖書館狀態。 – jww

3

的快速解決方案:git push -f

這迫使推動並覆蓋遠程歷史。 如果有其他人使用這個遠程倉庫:不要這樣做!

從遠程存儲庫中提取的其他人將遇到問題,因爲他們的歷史不再是存儲庫歷史記錄的子集。大多數項目禁止強行推送。

更好的解決方案是爲您的更改創建一個新的提交。無論是

  • git revert hashes
  • git checkout oldversion .; git add/commit

這然後創建你的歷史之上,描述返回到任何你想要的版本需要變化的新承諾。

+0

*「更好的解決方案是爲您的更改創建一個新的提交...」 - 這就是我們正在嘗試做的事情。我們希望下一次提交將事情改回到基於當前狀態的事情上。 – jww

+0

辦'git checkout 66ada4cc61d62afc。; git add。; git commit -m「foo」' 'git checkout version'給你帶來信息分離頭,'git checkout version filename'獲取歷史文件 –

+0

@RobinRoth'git checkout .'不會刪除文件。一種更安全的方法是'git checkout && git reset --soft master && git commit' – poke