Azi
Azi

Reputation: 199

Restrict cherry-picks to GIT

We would like our developers to not make cherry-picks at all and follow the our standard branching strategy. We use bitbucket. Is there a simple way to forbid making cherry-picks? Google didn't help there and the only way to do it is to develop a git hook - time-consuming option.

Thank you in advance!

Upvotes: 2

Views: 525

Answers (2)

Code-Apprentice
Code-Apprentice

Reputation: 83517

This problem requires a human solution, not a technical one. Put in place conventions and use code reviews to monitor this.

Note that git cherry-pick in and of itself is not necessarily bad. Sometimes I am working on a branch and muck everything up enough that I need to start over with a new branch. However, there are often some small commits from my old branch which I have high confidence in their quality. I cherry pick these commits to the new branch. My final pull request after all the work is completed comes from the new branch, so there are no commits which duplicate the same textual code change.

I find that this often helps reduce the time spent backtracking on a broken branch. Disabling cherry picks completely would hinder me in such situations.

Upvotes: 1

Mark Adelsberger
Mark Adelsberger

Reputation: 45659

Realistically there's nothing the tools can do. The cherry-pick command just automates the creation of a commit whose patch happens to match that of another existing commit; there is nothing special about the resulting commit, so even a hook wouldn't really have a way to pick out the fact that a commit was cherry-picked.

I say this as someone who doesn't really like cherry-pick - or, at least, thinks it's over-used and over-recommended. But even if you found a way to prevent cherry-pick, a dev wanting to do it could just work out the simple rebase approach to do the same thing. Or they could manually generate the patch for the source commit and manually apply it to the target branch, making it indistinguishable from a hand-coded commit in terms of the git commands issued.

And that last sentence should make clear, even if you change source control tools to one that doesn't have a concept of cherry-pick, the devs can still do the same thing by hand, if it's what they feel motivated to do.

Sometimes the problem isn't a technical problem.

Upvotes: 4

Related Questions