Wednesday, April 13, 2022

Git squash/rebase

You may got code conflict when a PR created, In the case you can rebase the branch:

git checkout feature/RealSense

Delete local master in case it is messed up:

git branch -D master

git checkout master

 git pull

 Check in feature branch

git checkout feature/RealSense

git push

Rebase local master 

git rebase master

To abort rebase 

git rebase --abort

Squash the multiple commits (55 limit, if you have more than 55, you can split them) into 1 commit in branch feature/RealSense

git rebase -i HEAD~2

During above process, if you choose to git rebase --skip, you will find differences between your branch and the consolidation branch.


Create a new branch feature/RealSense-squash from current branch  feature/RealSense, run below command, there should not be any difference:

git diff feature/RealSense..eature/RealSense-squash

Once you confirm no difference, you can push to remote organ:

git push --force

Rebase local master then push to origin with force 

git rebase master

git rebase --continue

git push --force

The code conflicts should be cleaned up now. 

No comments:

Post a Comment