如何在Git中进行合并而不更改master中的配置文件? [英] How can I merge in Git without changing config files in master?

查看:220
本文介绍了如何在Git中进行合并而不更改master中的配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有许多配置文件,其中包含需要为我们的开发人员环境修改的信息,例如url。我们在git中创建开发环境作为分支,并对配置文件进行更改。问题是,当我们将开发分支合并回主分支时,它会更改主分支中的配置文件。



我们希望将文件存储在git ,所以我不相信我们可以使用.gitignore。我们需要将所有源代码保存在回购库中,因为我们使用弹性beanstalk,并且每次都需要部署整个源代码。



我们尝试使用.gitattributes ,并阅读了许多帖子,例如,但似乎是您设置的合并驱动程序。只有在两个文件发生变化时才会调用gitattributes。在我们的例子中,我们不会更改主分支中的配置文件,所以合并驱动程序永远不会被调用。



有没有简单的方法来做到这一点,而不写一个脚本?

解决方案

在研究了诸如rebase和fetch之类的许多git命令之后,我找到了一个简单的方法来完成这个任务。只需将分支创建为孤立分支,将配置文件复制到它,然后使用命令git checkout configs_branch - 。实质上将配置文件复制到父分支。




$ b

p> git remote add origin(远程仓库URL)



确保您位于您想从创建分支的分支中

>

创建将包含配置文件作为孤立分支的分支,以便分支不包含所有源代码

git checkout --orphan configs_branch



将配置文件复制到repo的这个分支中,添加文件,提交和推送



Git add。



Git commit -m初始提交配置文件 p>

git push origin configs_url


$ b 成功合并后



来自母公司h



git checkout parentbranchname



git fetch --all


将文件从配置分支复制到父分支



git checkout configs_branch - 。



(您在上述命令后仍然会在父分支上)

提交文件



git commit -m重置配置文件



感谢@vampire的帮助!


We have a number of configuration files that contain information, such as a url, that need to be modified for our developer environment. We create the developer environment as a branch in git, and make the changes to the configuration files. The problem is that when we merge the development branch back to the master branch, it changes the configuration files in the master branch.

We would like to store the files in git, so I do not believe we can use .gitignore. We need to keep all of our source in the repo since we are using elastic beanstalk, and need to deploy the entire source each time.

We have tried to use .gitattributes, and read many of the posts, such as How do I tell git to always select my local version for conflicted merges on a specific file?, but it appears that the merge driver that you setup in .gitattributes will only be called if there is a change to both files. In our case we will not be changing the configuration files in the master branch, so the merge driver is never called.

Is there an easy way to do this without writing a script?

解决方案

After researching a number of git commands such as rebase and fetch, I found a simple way to do this. Just create the branch as an orphan, copy the config files to it, and use the command "git checkout configs_branch -- . " to essentially copy the config files to the parent branch.

So in detail:

initialize the git repo with the repo url

git remote add origin (remote repository url)

make sure you are in the branch you want to create the branch from

create the branch that will contain the config files as an orphan branch so that the branch does not contain all of your source

git checkout --orphan configs_branch

copy the config files to this branch of the repo add the files, commit, and push

Git add .

Git commit -m "initial commit with config files"

git push origin configs_url

AFTER A SUCCESSFUL MERGE

from parent branch

git checkout parentbranchname

git fetch --all

copy the files from the config branch to the parent branch

git checkout configs_branch -- .

(you will still be on the parent branch after the above command)

commit the files

git commit -m "resetting the config files"

Thanks @vampire for your help!

这篇关于如何在Git中进行合并而不更改master中的配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆