忽略git中的服务器配置文件 [英] Ignoring server config files in git

查看:84
本文介绍了忽略git中的服务器配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web项目中有一个文件用于设置站点数据库连接.显然,这对站点的暂存和实时分支具有不同的设置,我需要它在计算机上包含本地开发设置.该文件需要存储在存储库中,但是现在它已经存在,不再需要跟踪.

I have a file in my web project that sets up the site db connection. Obviously, this has different settings for the staging and live branches of the site, and I need it to contain my local dev settings on my machine. The file needs to be in the repo, but now that it's there it doesn't need to be tracked.

我已遵循此问题(和其他问题)的建议:如何仅在git中本地忽略文件?这已经停止了git,告诉我有关更改的信息给定的分支,但是如果我尝试更改分支,例如从我当前的错误修复分支转换为暂存,或者如果我尝试将暂存合并到当前分支,则git警告我本地更改将被覆盖,并且我被锁定了在分支中.

I've followed the advice in this question (and others): How to ignore files only locally in git? which has stopped git telling me about changes on a given branch, but if I try to change branches, say from my current bug fixing branch into staging, or if I try to merge staging into the current branch, git warns me that the local changes will be overwritten, and I'm locked in the branch.

到目前为止,我发现的唯一解决方案"是取消忽略文件,提交差异或修改本地文件以使其与服务器分支匹配.

So far the only 'solution' I've found has been to un-ignore the file, and commit the differences, or modify my local file so it matches the server branch.

让所有分支都忽略配置文件的最佳方法是什么?

What's the best way to get all branches ignoring the config file?

推荐答案

尝试忽略git中仅对跟踪文件的本地更改只会导致问题.

Trying to ignore local-only changes to tracked files in git will only result in problems.

--assume-unchanged和--skip-worktree之类的选项仅在执行git status时起作用,当git从文件系统读取更改时.当您执行git checkout之类的操作时,git不会忽略对这些文件的更改,从而给您带来运行错误.

Options like --assume-unchanged and --skip-worktree only have influence when doing git status, when git reads change from the filesystem. When you do operations like git checkout, git will not ignore changes to these files, giving you the errors you run into.

以我(和其他)的经验,最好不要跟踪实际配置文件.相反,最好以其他名称跟踪模板.这样可以避免很多问题,这些问题会覆盖实际的配置文件,或者在复制/提取文件时不得不排除/忽略文件.

In my experience (and others), it's better to not track the actual config files. In stead, it's better to track a template under a different name. This prevents a lot of issues of overwriting the actual config file or having to exclude / ignore files when copying / extracting files.

这篇关于忽略git中的服务器配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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