What is the purpose of a separate merge commit in git?

前端 未结 2 2187
囚心锁ツ
囚心锁ツ 2021-02-13 23:46

When you merge two branches together, git creates a separate commit with a message like Merge branch \'master\' into my-branch. For a non-trivial merge it is clear

2条回答
  •  孤独总比滥情好
    2021-02-13 23:59

    I think there are several reasons why having separate merge commits is a good idea, but it all comes down to the basic rule, that every commit should contain changes that belong together.

    Possible situations where you will benefit from having separate merge commits:

    1. You're trying to find out which commit introduced a bug. If you don't separate merging and normal commits, it's hard to figure out whether the merge caused that bug, or the actual changes from that commit.
    2. You want to revert a change made by a commit. What should happen when you're reverting a commit that is a merge and also contains changes on its own? Do you want to revert just the changes, or just the merge, or both? If only one of them, how to separate them?

    As added benefit, you get history that's easier to understand. (You could get history that's even easier to understand if you used rebase, but you said that's not possible.)

提交回复
热议问题