git reabse - compress/squash multi commits to one

by command line

git rebase -i HEAD~N

pick c3d4e5f First commit
squash b2c3d4e Second commit
squash a1b2c3d Third commit

git push --force-with-lease

by idea

rebase from any commit

switch to target branch. right click on base commit, choose "Interactively Rebase from Here...", multi-select commits you want to compress, click "Squash", type commit msg, click "Start Rebasing", when finished, run git push --force-with-lease.

example:

git log --oneline

a1b2c3d Third commit
b2c3d4e Second commit
c3d4e5f First commit

if you want to compress/squash this three commits to one, just right click commit "c3d4e5f"
even you can compress c3d4e5f and b2c3d4e to a new commit, which does not affect a1b2c3d.

by tortoiseGit

作者:admin  创建时间:2025-06-25 19:41
最后编辑:admin  更新时间:2025-09-19 10:08