.gitignore - 将文件保存在GitHub上 [英] .gitignore - keeping files on GitHub
问题描述
有很多类似的问题,但是没有一个能够实现所需的解决方案。
如何忽略对本地文件的更改而不将其提交给github?示例:app / etc / local.xml
Github - 具有正确的local.xml,不应该被覆盖!
我有一个包含app / etc / local.xml的本地.gitignore文件
但是,当我更改文件时,它仍然显示为已修改的提交。
我曾尝试过:
git rm - 高速缓存的应用程序/ etc / local.xml
code>
,但是这会从github中删除文件,不过它可以让我继续在本地编辑文件,它不会出现在提交中。
如何将原始文件保存在github上?
这是与我的.gitignore中的所有文件和文件夹保持一致
您正在寻找错误的方向。 b
问题的常见解决方案是创建两个文件:
app / etc / local.xml.dist
- 为其中的所有设置设置合理的默认值,并将其添加到 Git
存储库中;
app / etc / local.xml
- 将您实际使用的值放入您的计算机在这个文件中,不将它添加到 Git
存储库(如果它已经存在,则将其删除)并将其路径添加到 .gitignore
。
在 local.xml.dist中添加注释
教你的开发伙伴他们应该复制这个文件,把它命名为 local.xml
,并把它们的实际配置值放在里面(而不是为此目的修改 local.xml.dist
)。
编写代码读取然后,如果
local.xml
存在,则加载它并覆盖从 local.xml加载的值。 DIST
。这样 local.xml
只能包含真正需要设置的值;如果 local.xml.dist
已经提供了一个可以在本地计算机上使用的默认值,它可以从 local.xml
。
现在很多软件包都是这样工作的。
There are many questions like this, however none seem to achieve the solution required.
How do I ignore changes to a local file without being committed to github? Example: app/etc/local.xml
Github - Has the correct local.xml this should not be overwritten! I have a local .gitignore file that contains app/etc/local.xml However when I change the file it still shows up as modified for commit.
I have tried:
git rm --cached app/etc/local.xml
but this deletes the file from github, however it does then let me continue to edit file locally and it does not appear on a commit.
How do I keep the original file on github?
This is consistant with all files and folders in my .gitignore
You are searching in the wrong direction.
The common solution for your problem is to create two files:
app/etc/local.xml.dist
- put reasonable default values for all the settings in it and add it to theGit
repository;app/etc/local.xml
- put the values you actually use on your computer in this file, do not add it to theGit
repository (remove it if it already exists) and add its path to.gitignore
.
Add a comment into local.xml.dist
to teach your fellow developers they should make a copy of the file, name it local.xml
and put their actual configuration values in it (and not modify local.xml.dist
for this purpose).
Write the code to read local.xml.dist
then, if local.xml
exists load it and overwrite the values loaded from local.xml.dist
. This way local.xml
can contain only the values that really need to be set; if local.xml.dist
already provide a default value that can be used on the local computer it can miss from local.xml
.
This is how a lot of software packages work these days.
这篇关于.gitignore - 将文件保存在GitHub上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!