简体   繁体   English

忽略git中的本地配置文件

[英]ignoring local config files in git

There are some local files (that are part of our repository) in a rails app that I would like git to ignore. 在rails应用程序中有一些本地文件(属于我们的存储库的一部分),我希望git忽略它们。 Basically, I'd like git to ignore all changes I make to anything in the config/environments directory and to the config/application.rb file. 基本上,我希望git忽略我对config / environments目录和config / application.rb文件中所做的任何更改。 I don't want to use .gitignore because I don't want OTHER people working on the code base to have their configurations ignored by git. 我不想使用.gitignore,因为我不希望其他人在代码库上工作,让git忽略他们的配置。 Basically I'm doing a lot of testing that modifies the config files and sometimes my config changes are checked into a github which at a minimum is embarassing and at worst causes issues with the production environment. 基本上我正在进行大量的测试来修改配置文件,有时我的配置更改会被检入github,这至少会令人尴尬,最糟糕的是会导致生产环境出现问题。

What's the best approach here? 这里最好的方法是什么?

You can set up a global .gitignore . 您可以设置全局.gitignore

Although, it will still see changes in files that already are in the repository. 虽然,它仍然会看到已存在于存储库中的文件中的更改。 Here's how you work around this . 这是你如何解决这个问题 You can probably make a bash macro out of it. 你可以用它来制作一个bash宏。

You can do git update-index --assume-unchanged config/application.rb and git will not notice any changes you make to the local copy of that file unless you explicitly use git add . 您可以执行git update-index --assume-unchanged config/application.rb ,除非您明确使用git add ,否则git不会注意您对该文件的本地副本所做的任何更改。

My understanding is that .gitignore and friends won't change how files that are already put into the repository are handled, only whether untracked files are presented as candidates. 我的理解是.gitignore和朋友不会改变已经放入存储库的文件的处理方式,只会改变未跟踪文件是否作为候选文件。

您可以定义一个全局.gitignore ,它将是您的机器特定的,而不是签入项目存储库。

check for the .gitignore file.If not just create a file .gitignore and mention the list of files you want to ignore like this config/database.yml 检查.gitignore文件。如果不是只创建一个文件.gitignore并提及你要忽略的文件列表,如config / database.yml

 /config/*.yml
/log/*.log /tmp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM