2017-02-25 100 views
1

我試圖從多個提交(它已被推送到起源/主)作出一個提交。GIT rebase - 多個提交到一個 - 仍在歷史中看到

我從本教程嘗試它: https://feeding.cloud.geek.nz/posts/combining-multiple-commits-into-one/

$ git log --oneline 
c172641 Fix second file 
24f5ad2 Another file 
97c9d7d Add first file 
we can combine the last two commits (c172641 and 24f5ad2) by rebasing up to the first commit: 

$ git rebase -i 97c9d7d 
and specify the following commands in the interactive rebase screen: 

pick 24f5ad2 Another file 
squash c172641 Fix second file 
which will rewrite the history into this: 

$ git log --oneline 
1a9d5e4 Another file 
97c9d7d Add first file 

這工作不錯,直到我把它推到原點/主。

$ git pull 
$ git push origin master 
$ git log --oneline 

RESULT IS: 
******* Merge branch master... 
******* THAT REBASE name... 
c172641 Fix second file 
24f5ad2 Another file 
97c9d7d Add first file 

但我想這樣的結果:

$ git log --oneline 
1a9d5e4 Another file 
97c9d7d Add first file 

這可能嗎?

+1

從「一隻狗」獲取幫助:運行'git log --all --decorate --oneline --graph'。合併後,您可以省略「全部」部分。請記住,*從不使用'git pull' *,首先使用'git fetch',然後使用DOG,*然後*合併*如果* DOG說它沒問題。 :-) – torek

回答

1

在這種情況下,你可能想推而不是拉&推

$ git log --oneline 
1a9d5e4 Another file 
97c9d7d Add first file 

$ git push -f origin master 

通知:rebase + force push覆蓋歷史,慎用公共分支使用。

+0

我試了一下,但是我得到了「一切都是最新的」 –

+0

'git stash'然後'git reset --hard 1a9d5e4; git push -f origin master'? – Xlee

+1

非常感謝你的推動力!我沒有注意到我處在rebase中間...我解決了衝突,使用git rebase - 繼續,然後用力推它來掌握:) –

相關問題