尝试git rebase -i并将之前的提交压缩成一个,但它会删除我最近的更改

时间:2017-07-21 07:29:03

标签: git github version-control gitlab rebase

我在分支主机上的git历史记录如下:

ee040dd Me success project build with all changes I want to keep in this commit since it already merged
1e7282f Me fixing changes   
0a9fb50 Y User some commit    
e03d64e Z User some commit    
5567972 Z User some commit    
a54d24f Me adding new feature    
95d2c28 X User some commit    
7f7b8b2 Me previous commit

基本上对于代码推送我试图在ee040dd中发送所有更新的更改,但是我想将它们全部压缩到 最近的提交中而不是发送几次提交 由于许多合并和合并冲突。

当我git rebase -i ee040dd时,我会像往常一样获得以下文档:

pick 7f7b8b2 previous commit
pick a54d24f adding new feature
pick 1e7282 fixing changes

当我这样做时:

pick 7f7b8b2 previous commit
squash a54d24f adding new feature
squash 1e7282 fixing changes

似乎它把我所有的更改压缩到之前的提交,这不是我想要的(因为我在ee040dd中丢失了所有更改)

我该怎么办?

1 个答案:

答案 0 :(得分:0)

如果您想保留最新的提交ee040dd,则应在rebase交互式窗口中将其保留为pick

pick 7f7b8b2 previous commit
sqush a54d24f adding new feature
squash 1e7282 fixing changes
…
squash 1e7282f Me fixing changes 
pick ee040dd Me success project build with all changes I want to keep in this commit since it already merged

由于您已经压缩了最后一次提交,现在您可以在master分支的顶部挑选它:git cherry-pick ee040dd