2010-04-11 60 views
23

當我執行'git pull'時,我與頭部提交發生衝突。所以我做了'git rebase --abort'如何刪除我在本地git存儲庫中的上次提交

我可以'保存'我的提交到一個「補丁」,然後做一個git拉?

我想模仿是:

  • 我沒有犯,但我做了一個「git的藏匿」,而不是
  • 做一個混帳拉,以避免任何合併錯誤

所以我需要某種方式來「倒流時鐘」。這可能與git?

回答

56

7826b2補丁仍然會引起衝突時,它的拉力後應用,但你可以做到以下幾點:

git reset --soft HEAD^ 
git stash 
git pull 
git stash pop # Will cause a conflict 
git commit # Re-commit 7826b2 

另一個工作流,也可以:

git reset --hard HEAD^ 
git pull 
git cherry-pick 7826b2 # Will cause a conflict 

第二個工作流依賴Git保留7826b2在reflog中提交的事實(您可以將其視爲回收站),即使您重置第一行引入的更改也是如此。

0

有一個辦法,其實在混帳,我敢肯定有做着它的多種方式...

你可以這樣做:

git stash  # Stash your changes 
git pull  # Pull the changes 
git stash pop # Pop your stash 

你可以這樣做:

git pull --rebase # Bring in the changes and apply yours on top of it. 

你可以這樣做:

git stash  # Stash your changes 
git checkout <commit> # Pull a specific commit. 
git stash pop # Pop your stash 

希望它有幫助。

4

如果你沒有犯在本地資源庫的更改,你可以做一個直底墊:

混帳取起源

git的變基原產/主

這解開你的本地從本地主設備提交,應用來自原始/主設備的新提交,然後重播您的本地提交。

在你的情況下,這將導致衝突,git會告訴你哪些文件需要被編輯來解決衝突。這樣做後,git add這些文件,然後git commit沒有參數重新發送更改。

+0

這就是我一直在尋找因爲,太好了。 – 2013-05-14 08:20:50

0

首先,我建議做你的分支的備份:

git branch your_branch_backup 

那麼最簡單的方法是:

git reset --soft <commit> #Go back in time but without loosing your changes 
git stash     #Stash your changes 
git pull     #Refresh your branch with origin 
git stash pop    #Re-apply your changes on the refreshed branch 

然後你可以提交照常

相關問題