Merge all commit (modifications) on a branch into one commit:git merge --squash feature
Applicable scenarios:
This version has been modified a lot, and there are too many commits
1. For the convenience of viewing all modifications of a version in the future;
2. It is possible to roll back the merge online for the convenience of rolling back;
3. Make the whole version history of master clear and tidy;
Use this command whenever possible.
Examples:
Branch: master main branch, feature development branch
First, merge the master code into the feature branch to solve the code conflict between the branches;featue > git merge master
After the conflict is resolved, open a new online branch release from the mastermaster > git checkout -b release
On the release branch, merge develops the branch featurerelease > git merge --squash feature
After execution, GIT status will view the current branch status, and you will see that all the modifications on the feature branch have been on the online branch release and are in the uncommitted state. At this time, GIT commit will merge all the modifications into one commitRelease > git commit - am "version XXX, modify XXX, go online"
Then push online branch to gitlab warehouserelease > git push origin release
Finally, submit merge request on gitlab and apply for online