Is there a way to keep two branches from merging in git

前端 未结 2 774
傲寒
傲寒 2021-01-05 10:56

I would like to be able to keep two separate branches in a git repo that cannot accidentally be merged even though the branches may contain similar content.

Is there

相关标签:
2条回答
  • 2021-01-05 11:30

    Note that a git merge with auto-commit would not call the pre-commit hook. See "git merge auto-commit doesn't fire pre-commit hook"

    Merge calls commit_tree directly, so the standard commit hooks are bypassed.

    A Patch is in progress.

    0 讨论(0)
  • 2021-01-05 11:38

    I believe the only way you could accomplish this is with a pre-commit hook. From the manpage:

    This hook is invoked by git commit, and can be bypassed with --no-verify option. It takes no parameter, and is invoked before obtaining the proposed commit log message and making a commit. Exiting with non-zero status from this script causes the git commit to abort.

    So, if you really want to, you can write a pre-commit hook which checks the current branch and the branch you're attempting to merge, and exits with non-zero status if it's the pair you don't want. Off the top of my head, the only way I can think of to check what branch you're attempting to merge is to examine the file .git/MERGE_MSG and parse the first line. (The alternative, .git/MERGE_HEAD will tell you the SHA1 you're merging, but with no record of what branch it was, so if two branches are in the same place, you're out of luck.

    The pre-commit hook is obviously not run for fast-forward merges; I doubt there's really any way to protect against that. But presumably if you keep the branches from being merged, there won't ever be a fast-forward attempt.

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