简体   繁体   English

git中的生产和开发分支如何维护?

[英]how to maintain a production and development branches in git?

In my project i have this constants.ts file which stores my API_URL .在我的项目中,我有这个存储我的API_URLconstants.ts文件。 I want to keep two API_URLs in my production(main) and development branches.我想在我的生产(主要)和开发分支中保留两个 API_URL。

ex: development -> API_URL = 'http://localhost:4000' main -> APIURL = 'https://backend.com'例如:开发 -> API_URL = 'http://localhost:4000' main -> APIURL = 'https://backend.com'

but when I change the API_URL and commit when it comes to merging the main and the development branch it detects as a change.但是当我更改 API_URL 并提交合并主分支和开发分支时,它检测为更改。 so if I merge it constant file in main branch will be also changes.所以如果我在主分支中合并它的常量文件也会发生变化。 How to ignore the changes of this file?如何忽略此文件的更改?

In my project, I have this constants.ts file which stores my API_URL .在我的项目中,我有这个存储我的API_URLconstants.ts文件。

The idea would be to store two files:这个想法是存储两个文件:

  • constants.ts.main
  • constants.ts.dev

(I use main instead of master here ) (我在这里使用main而不是master

  • keep constants.ts ignored from now on: echo constants.ts>>.gitignore .从现在开始忽略constants.tsecho constants.ts>>.gitignore

That means generating the right constants.ts file locally: no complex merge involved when merging dev to main .这意味着在本地生成正确的constants.ts文件:将dev合并到main时不涉及复杂的合并。

In each branch, you would then generate constants.ts , with the right content in it, from one of those files, depending on the current execution environment.然后,在每个分支中,您将根据当前的执行环境,从其中一个文件中生成包含正确内容的constants.ts

The generation script will determine the name of the checked out branch with:生成脚本将确定签出分支的名称:

branch=$(git rev-parse --symbolic --abbrev-ref HEAD)

Finally, you would register (in a .gitattributes declaration ) a content filter driver .最后,您将注册(在.gitattributes声明中)内容过滤器驱动程序

弄脏 (image from " Customizing Git - Git Attributes ", from " Pro Git book ") (图片来自“ 自定义 Git - Git 属性”,来自“ Pro Git 书”)

The smudge script, associated the constants.ts file, would generate (automatically, on git checkout or git switch ) the actual constants.ts file by looking values in the right constants.ts.<branch> value file.constants.ts文件关联的smudge脚本将通过查看正确的constants.ts.<branch>值文件中的值来生成(在git checkoutgit switch时自动生成)实际的constants.ts文件。
The generated actual constants.ts file remains ignored (by the .gitignore ).生成的实际constants.ts文件仍然被忽略(由.gitignore )。

See a complete example at " git smudge/clean filter between branches ".请参阅“ git 涂抹/清洁分支之间的过滤器”中的完整示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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