Is it possible to configure git to prevent reloading of already published commits?

I want to use git pull --rebase instead of merging, but with this approach, you can accidentally overwrite commits that have already been ported to another console.
In this case, a click merge is required.

Is there a way to configure git, so it rejects rebase if some of the commits to be reinstalled have already been ported to another remote?

+7
git
source share
2 answers

Try the following command:

 git rebase --onto <remote>/<branch-name> $(git rev-list HEAD \ --not --exclude=$(git rev-parse --symbolic-full-name HEAD) \ --glob=refs/* --reverse | head -1)~ 

This will only rearrange the commits that were made in the current local branch.

If you want to include local changes in other branches that have not been clicked, change the expression --glob=refs/* to --remotes . Keep in mind, although you can promote these local branches in the future, so use them with caution.

Explanation: Of course, since you are not using git pull , you will need to do git fetch before rebooting. (I prefer git fetch + git rebase or git merge , so that I can control what I rebuild or merge.)

+1
source share

You can write a hook to check if there is any commit in the range of commits in the target branch, if that's the way you want (e.g. push reject)

Using the git git branch --contains <commit1> ... <commit_n> , you can check if the give branch contains any of these commits.


Sumarry

git has nothing for you, you will have to write some custom code for this , but you can use git branch --contains to find out if the branch already has a given commit in it.

0
source share

All Articles