开发者

Keeping two Git branches different by one file

开发者 https://www.devze.com 2023-01-22 07:22 出处:网络
I am certain two branches of my Git repo should only ever be different in a single file. The simplest way to ensure this is to do all work in branch1, and merge it into branch2 whenever I switch to it

I am certain two branches of my Git repo should only ever be different in a single file. The simplest way to ensure this is to do all work in branch1, and merge it into branch2 whenever I switch to it (wrapped into开发者_StackOverflow中文版 a shell script, so I only need one command per switch). However, is there a way to do this with even less work?


Yes, use a git filter driver, with a smudge script intelligent enough to:

Keeping two Git branches different by one file

  • recognize it is dealing with that single file (reminder: such a script only deals with file content, not filename)
  • put the right content depending on the current branch.

But the question is: do you need two branches at all?
If this is a config file, as mentioned in "Git: how maintain (mostly) parallel branches with only a few difference?", storing templates might be better. That same question proposes other alternatives.

0

精彩评论

暂无评论...
验证码 换一张
取 消