Git merge flattening

前端 未结 3 1453
遥遥无期
遥遥无期 2020-12-08 00:46

If I am working in multiple branches on a single feature, I use git pull branch1 branch2 branch3 to pull all the changes into my master branch. However, all the

3条回答
  •  半阙折子戏
    2020-12-08 01:00

    As Brian White commented the problem with git merge --squash is that it gives you no visible link, and therefore no traceability back to the branch (or the individual changes) you merged in.

    Visibly (when viewed as a graph git log --graph), an important branch that has been merged back in looks no different to an experimental branch that you messed around with and would happily discard. Both are just hanging there unconnected to anything. I personally want to know that a certain branch has been merged back in so I know that work is done.

    A solution that works for me is to use a merge with the no-fastforward option.

    git merge --no-ff somebranch -m "my commit message"
    

    This forces git to create a single commit with all the branch changes included, you can set the commit message yourself (if you want) BUT most importantly, it links the new commit back to the branch it just merged in. This visibly shows that work on that branch is complete but also allows you to trace back to see details of the individual commits from the merged branch.

    Here is an example where very simple branches with one and two commits respectively have been merged back into master. I have subsequently deleted the branch tags on the merged branches, however the branch name can still be seen on the merge commit message. The branch name should summarise the changes and if you want to know the exact changes contained you can trace it back to the individual commits. This approach seems to work nicely for simple projects.

    Note : I had to manually draw one of the connectors in as it was such a dark blue it was barely visible.

提交回复
热议问题