简体   繁体   中英

How to forbid Git merge certain branches

I need support of 3 versions of my program. Where most files are

joint (common) but several files contain different content for each version.

I'll probably use 4 branches A,B,C,D in Git.

Form example project Ice-cream:

____________________________________________________
Cup.txt: { Waffle cup } – common file for all version

Filling.txt { banana } - special file for B version
Filling.txt { strawberries } - special file for C version
Filling.txt { vanilla } - special file for D version
____________________________________________________

A - branch suitable only for global files (Cup.txt)

B,C,D - branch suitable only for Filling.txt file.

For this strategy I need allow to merge only in one direction: A => B,C,D

My question is how to forbid merging from B,C,D to A branches in Git?

如何禁止合并反向

Regarding source code, it is best to avoid complex merge strategy, and modify PrintBill in order to:

  • separate content specific to client A and B
  • build the right executable for client A and client B by choosing the right source

The idea is the same than the one initially written below: avoid any complex merge strategy.

Now if that kind of refactoring isn't possible, you can try and declare a merge driver , but that won't be always called (only in case of conflicts)


Another approach would be to avoid versioning Filling.txt (that way, no more merge strategy headache).

You can:

  • version 3 different files with values for each environment
  • setup a smudge script (a content filter driver declare in a .gitattributes file ) which will automatically on checkout generate, depending on the checked out branch, the right Filling.txt

涂抹

Firstly, I don't think this is really what you want to do.

You want to forbid merging in B-specific stuff into A.

But merging general bug fixes from B to A should be fine.

So you should keep B-specific stuff in separate files.

Anyway, what you need is something like a git pre-receive hook on the "central server", which checks for and prevents additions of "banned files", I think.

But note that if you do keep B-specific stuff in separate files, you don't even need to use git branches to solve this problem. You can just use separate projects with dependencies between them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM