Can git be configured to prevent rebase of already published commits?

后端 未结 2 1444
北恋
北恋 2021-01-02 09:13

I want to use the git pull --rebase instead of merge but with this approach one can accidentally rebase commits that were already pushed to another remote.

2条回答
  •  我在风中等你
    2021-01-02 09:44

    You can write hook that check to see if any commit within the range of the commits are already in the targeted branch, if so do what ever you want (like rejecting the push)

    Using the git commands git branch --contains ... you can check if the give branch contains any of the given commits.


    Sumarry

    git does not have anything out of the box for you, you will have to write some custom made code to do it, but you can use the git branch --contains to find out if the branch already has the given commit in it.

提交回复
热议问题