Keep commits history after a 'git merge'

后端 未结 2 1738
悲哀的现实
悲哀的现实 2020-12-13 13:35

When I work on two different features (on two different branches created from the master) it is quite annoying that I will not have the commit history when I procee

2条回答
  •  再見小時候
    2020-12-13 14:15

    Use rebase instead of merge. From the tutorial:

    If you examine the log of a rebased branch, it looks like a linear history: it appears that all the work happened in series, even when it originally happened in parallel.

    I imagine that the changes from your Branch-B cannot be merged using fast-forward merging into the master. In such cases a three-way-merge is done:

    Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it. This is referred to as a merge commit, and is special in that it has more than one parent.

    I would always rebase my commits before commiting them into the master to keep the linear history.

提交回复
热议问题