A lot of work was done on a feature branch, and during this time, there were multiple commits on the branch but also merge commits with changes from the main branch.
Now the feature branch has commits like this:
Now there is a pull request created on the GitHub repo, but it's hard to follow through the all the changes and approve it.
What I would like is to squash commits made on the feature branch, such that I will have just one nice commit which I need to review.
How can I do that?
I've read about squashing changes and rebasing, but I need some help. Can I just call rebase -i [commitnumber]
where commit number is of Work 1
? I used this on feature branches and it worked great but not when merge commits exist.
git merge --squash
That's the simplest way. Go to your main
branch and merge the feature
branch using the --squash
option.
git checkout main
git merge --squash feature
git rebase -i
This would be what you suggested. Before rebasing make sure you have a backup copy of your feature branch. On your feature branch invoke git branch
:
git checkout feature
git branch feature_backup
Now check the log for the SHA hash of the commit where the development of your feature has started. If this was a long time ago, you can use this command to see where the feature
branch splitted from the main
branch:
git merge-base main feature
Then use git rebase :
git rebase bc4b30e
Proceed like it is described here . You're not supposed to give the number of commits you want to squash but to give the SHA hash of the first commit you want to squash. You can use HEAD~n
if that was n commits ago.
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.