Git remove and squash commit

pleng
1 min readJun 6, 2023

remove remote commit

  • start with this command
git rebase -i origin/master

will display

pick d1b8dbb5 add aa config
pick d1b8dbb6 add bb config
pick d1b8dbb7 add cc config

press i and edit which commit to drop change pick to d

pick d1b8dbb5 add aa config
d d1b8dbb6 add bb config
pick d1b8dbb7 add cc config

add press esc and input

:wq

check log

git log

will display

pick d1b8dbb5 add aa config
pick d1b8dbb7 add cc config

force push

git push --force

squash commit

  • start with this command
git rebase -i origin/master

will display

pick d1b8dbb5 add aa config
pick d1b8dbb6 add bb config
pick d1b8dbb7 add cc config

press i and edit all commit to s except last commit

s d1b8dbb5 add aa config
s d1b8dbb6 add bb config
pick d1b8dbb7 add cc config

add press esc and input

:wq

check log

git log

will display

pick d1b8dbb7 add cc config

force push

git push --force

--

--