如何忽略Git合并中的文件? [英] How to ignore files in Git merge?

查看:350
本文介绍了如何忽略Git合并中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个(Django)网站上有两个分支: master dev

I'm working on a (Django) website with two branches: master and dev.

master 是正式版本,此处不应直接进行任何工作。一旦认为稳定,所有更改应来自合并 dev 分支。

master is the production version and no work should be done here directly. All the changes should come from merging dev branch, once it is considered to be stable.

<$ c $您可能会猜到,c> dev 是开发分支,所有更改都在这里(和子分支)进行。

dev, as you may guess, is the development branch and all the changes are made here (and subbranches).

在服务器中我有两个网站在工作,一个是生产网站(使用 master 分支),另一个是私有开发网站,其中有 dev 子域,使用 dev 分支。

In the server I have two websites working, the production one (uses master branch) and another private for development, with dev subdomain that uses dev branch.

问题是所有配置文件,静态文件(图像等)都是内部控制版本,以便能够轻松将它们推入服务器。但是,如果在 dev 中修改了这类文件(静态,配置...)以仅在服务器中调试,然后需要与主服务器合并... 将dev合并到master时如何设置一些文件和目录忽略?

The problem is that all the configuration files, static files (images, etc.) are inside the control version to be able to easily push them to the server. But, if these kind of files (static, config...) are modified in dev to just debug in the server and then I need to merge with master... How can I set some files and dirs to be ignored when merging dev into master?

我一直在搜索,发现一些< a href = https://stackoverflow.com/questions/3868491/git-ignore-some-files-during-a-merge-keep-some-files-restricted-to-one-branch>相关问题,但它们告诉您将 .gitattributes merge = ours 一起使用。但是,这种方法有一个很大的警告:仅当在两个分支中修改了文件时,才应用该策略,但这不是我的情况。

I've been searching and I've found some related questions, but they tell you to use .gitattributes with merge=ours. However, this approach has a big caveat: it only applies the strategy if the file is modified in the two branches, but this isn't my case.

关于

推荐答案



git checkout master

git merge --no-log --no-ff --no-commit dev

git checkout master <files-you-don't-want-to-merge>


git add <files-you-don't-want-to-merge>

git commit -a

~~~ Test / Build ~~~

git push origin master 


这篇关于如何忽略Git合并中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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