[Go] git merge combines multiple commit into one -- squash Option

Source: Internet
Author: User

[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--squashOptions are as follows:

$ git merge --squash another$ git commit -m "message here"

 

-- Squash:

--squashThe 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 additionalcommitCommand. The effect is equivalentcommitMerge them into one and put them on the current branch. The originalcommitHistory is not taken.

Determine whether to use--squashThe 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.

OnlycommitIt 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 retaincommitHistory.

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.