[From] 80333645
1. General Practice (direct git merge)
One of the major advantages of git over CVs and SVN is that merge is very convenient. Just point out the branch name, for example:
$ git merge another$ git checkout another# modify, commit, modify, commit ...$ git checkout master$ git merge another
2. Improved Version: Merge multiple commits into one (GIT merge -- squash branchname)
However, the convenience of operations does not mean that such operations are reasonable. In some cases, we should prioritize the use--squash
Options are as follows:
$ git merge --squash another$ git commit -m "message here"
-- Squash:
--squash
The content of the local file is the same as that of the merge result without this option, but it is not submitted or moved.HEAD
, So an additionalcommit
Command. The effect is equivalentcommit
Merge them into one and put them on the current branch. The originalcommit
History is not taken.
Determine whether to use--squash
The most fundamental criterion of the option is whether the history on the branch to be merged is meaningful.
If the submission on the Development Branch is very casual or even written as a microblog, you must use--squash
. The version history should be the development of code, rather than the developer's activity in coding.
Onlycommit
It has its own meaning, and can be compiled through the case (can pass the test is more perfect), should choose the default merge method to retaincommit
History.
3. Experiment:
1.master's sub-branch only has one file 1.txt
2. Cut out a feature-squash branch and submit it three times.
3. Use the -- squash option merge for the feature-squash branch to go to the master branch. We can see that merge is playing, and a prompt will be prompted: Make a commit.
The new commit log is "execute git merge -- squash feature-squash"
4. Check the master branch, and find that multiple commits on squash are merged to be submitted in sequence.
4. Summary:
1. Dev "1.txt"
2. dev_jn "1.txt" another three times is equivalent to developing a new function. The submission records are:" 2.txt" "3.txt"" 4.txt"
3. Merge the "2.txt"," 3.txt", and "4.txt" commits on dev_jn into a large commit record" squash merge "for one commit;
4. Check the dev submission record. Only the "1.txt" and" squash merge "submission records are available to ensure the cleanliness of the submitted records on Dev.
[Go] git merge combines multiple commit into one -- squash Option