Git: Prevent fast-forward merges only when merging external branches into master

前端 未结 1 1230
有刺的猬
有刺的猬 2021-01-06 06:53

In order to make it easy to see when feature branches are merged to master, one can use Git\'s --no-ff option when merging their feature branch into master.

相关标签:
1条回答
  • 2021-01-06 07:43

    Note: a pre-merge hook doesn't exist.
    It was introduced in 2008, and criticized then (because the control had better be implemented on the server (using an update hook).
    It is in the process of being re-introduced (September 2012)

    And a pre/post-commit hook isn't run on the auto-commit done by a git merge.

    So:

    • either you put in place an update hook on a git server where developers are pushing (but that may be too late by then for them to realize they fast-forwarded a feature branch)
    • or you write (and distribute, and maintain...) a git-merge wrapper which will do that control at the local repo level.

    That being said, as I mentioned in "fast forward when using pull and no-ff when pull", not using --no-ff has its advantages, as it won't break git bisect and git blame.
    So a developer for a feature might want to reorganize his/her feature commits (squash them a little if there are too many of them) before fast-forward them in master branch (instead of creating one giant commit).
    See "Understanding the Git Workflow" for more.

    0 讨论(0)
提交回复
热议问题