简体   繁体   中英

Git squash specific commits

Im using the rebase tool to squash the last 3 commits and by mistake I did with git rebase -i HEAD~4 this command open the VI interactive tool like following


d 041a84a Fix docs buil(#4)
p 8896b6d handle users
s 8759e73 add new users
s b485efd add phones


the 041a84a is not related and I mark it as d but not sure if it will remove it from the this branch only or when I submit it to the master it still r emove it from the master which I DONT want, I just want to remove it from my branch … if I can exit from the VI tool and change it to git rebase -i HEAD~3 ??

If I understand correctly your problem your were in state such as this :

master :     --A--B 
branch :          \--C--C'--C"

Where:
B is 041a84a ;
C is 8896b6d ;
C' and C" must be squashed.

Now, if you apply

d B  Fix docs buil(#4)
p C  handle users
s C' add new users
s C" add phones

This should result in branches looking like :

master :    --A--B 
branch :       \--C*

This means that master will not be changed and only the history of the branch you are currently rebasing will be changed.

Finally, to answer "if I can exit from the VI tool and change it to git rebase -i HEAD~3" .
You can exit VI without writing anything with q! and then your are free to do git rebase -i HEAD~3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM