2017-02-25 54 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 - 继续,然后用力推它来掌握:) –