[英]How to maintain seperate files in dev and main branches and sub branches github
Question: When merging dev
into main
, how do I keep them .ebextensions
and .elasticbeanstalk
commited on their respective branches but never overwriting each other during merges?问题:当将
dev
合并到main
时,我如何让它们.ebextensions
和.elasticbeanstalk
在各自的分支上提交,但在合并期间从不相互覆盖?
Requirement: I wish to checkout new topic branches from dev
and merge them back into dev
, so these topic branches will need the same .ebextensions
and .elasticbeanstalk
folders to come with them.要求:我希望从
dev
中签出新的主题分支并将它们合并回dev
,因此这些主题分支将需要相同的.ebextensions
和.elasticbeanstalk
文件夹来附带它们。
Landscape: Working with Github on Flask project for Elastic beanstalk. Landscape:与 Github 合作开发 Elastic beanstalk 的 Flask 项目。
I have two primary branches
我有两个主要
branches
I have dev
set up for one Elastic beanstalk environment, and main
set up in another.我已经为一个 Elastic beanstalk 环境进行了
dev
设置,并在另一个环境中进行了main
设置。 This means I have two different versions of the .ebextensions
and .elasticbeanstalk
folders.这意味着我有两个不同版本的
.ebextensions
和.elasticbeanstalk
文件夹。
.
├── application.py
├── .ebextensions
├── .ebignore
├── .elasticbeanstalk
├── .gitignore
├── main.py
└── .vscode
I keep messing up the files and having to write them back in locally and push to remote again to fix them.我一直在弄乱文件,不得不将它们写回本地并再次推送到远程以修复它们。
Having read about a third of git-scm.com's
book so I think the solution will involve "onbranch:" includeIf
but the example is hard to follow.阅读了大约三分之一的
git-scm.com's
书,所以我认为解决方案将涉及"onbranch:" includeIf
,但这个 例子很难理解。
Surely I've missed something, it can't be an uncommon requirement.当然我错过了一些东西,这不是一个不常见的要求。
It seems you already found a possible workaround, but I'd like to propose an alternative solution in which you set Git to never overwrite specific files.您似乎已经找到了一种可能的解决方法,但我想提出一个替代解决方案,您可以将 Git 设置为从不覆盖特定文件。
This can be done by creating a .gitattributes file with a pattern matching your files, and then creating a dummy merge strategy.这可以通过创建一个与您的文件匹配的模式的 .gitattributes 文件,然后创建一个虚拟合并策略来完成。
A more in-depth discussion for this approach can be found here , with some more information here .可以在此处找到有关此方法的更深入讨论,并在此处提供更多信息。
I believe that in your case you could do something along the lines of我相信在你的情况下你可以做一些事情
git config --global merge.ours.driver true
echo ".ebextensions/* merge=ours" >> .gitattributes
echo ".elasticbeanstalk/* merge=ours" >> .gitattributes
Please do note that I'm not sure if passing a hole directory with a wildcard will work, though I imagine it should be possible.请注意,我不确定是否可以使用通配符传递孔目录,但我认为应该是可能的。
When you do actions in Git, nearly all of them only add data to the Git database was a line I read but didn't apply when trying to resolve this issue.当您在 Git 中执行操作时,几乎所有操作都只向 Git 数据库添加数据,这是我读过的一行,但在尝试解决此问题时并未应用。
Thanks to @torek for clarifying.感谢@torek 的澄清。
My summary solution is store all the files我的总结解决方案是存储所有文件
So now my file structure looks like所以现在我的文件结构看起来像
.
├── application.py
├── .ebextensions-dev
├── .ebextensions-main
├── .ebignore
├── .elasticbeanstalk-dev
├── .elasticbeanstalk-main
├── .gitignore
├── main.py
└── .vscode
When I want to deploy the application to the dev
Elastic beanstalk environment:当我想将应用程序部署到
dev
Elastic beanstalk 环境时:
-dev
from the end of the .ebextensions-dev
and .elasticbeanstalk-dev
folder names..ebextensions-dev
和.elasticbeanstalk-dev
文件夹名称的末尾删除-dev
。files='.elasticbeanstalk .ebextensions'
x='-dev'
for i in $files; do
mv $i$x $i
done;
eb deploy
eb deploy
-dev
back onto the end of the .ebextensions
and .elasticbeanstalk
folder names.-dev
添加回.ebextensions
和.elasticbeanstalk
文件夹名称的末尾。files='.elasticbeanstalk .ebextensions'
x='-dev'
for i in $files; do
mv $i $i$x
done;
vica-versa for main
main
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.