正确的git过程来更改不应该提交的文件? [英] Proper git procedure for changed files that shouldn't be committed?

查看:131
本文介绍了正确的git过程来更改不应该提交的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚继承了一个现有的代码库,其中包含多个配置文件。这些配置文件都是通用的,意味着要对其下载到的每台机器进行编辑和定制。 Git很明显地告诉我他们已经被编辑过,并且每次执行 git status 时总是在未进行提交的更改下显示它们。我怎么能忽略这些文件在git下?将它们添加到.gitignore不起作用,因为它们已被git跟踪。我不想提交任何回购,但同时我想告诉git不要在本地机器上跟踪这些文件。有没有办法做到这一点,我不知道?我知道我可以 git stash 他们,他们将不会再显示,但我觉得这不是真正意义上的......我错了吗? p>

不知道这是否会改变任何内容,但我在本地机器上使用git-svn与SVN服务器进行交互。

解决方案

我做了一些类似于David Schwartz的建议,即创建类似shell / template配置的东西,如 database.yml.template 然后复制该文件并将其配置为我的环境,如 database.yml 。然后,我可以 .gitignore 这些新文件。



如果您想要在不修改文件存在方式repo,然后:

  git update-index --assume-unchanged [文件名] 

会让git忽略对该文件的更改,但您必须意识到这一点。



更多资讯在这里: http://gitready.com/ intermediate / 2009/02/18 / temporary-ignoring-files.html

I just inherited an existing codebase that has multiple configuration files in it. These configuration files are all generic, meant to be edited and customized for each machine they are downloaded to. Git is (obviously) telling me that they have been edited and is always showing them under "changes not staged for commit" every time I do a git status. How can I ignore these files under git? Adding them to .gitignore doesn't work because they are already being tracked by git. I don't want to commit anything to the repo, but at the same time I want to tell git not to track these files anymore on my local machine. Is there a way of doing this that I'm not aware of? I know I can git stash them and they won't be shown anymore, but I feel that is not really what it was meant for... Am I wrong?

Not sure if this changes anything, but I am using git-svn on my local machine to interact with the SVN server.

解决方案

I do something like David Schwartz suggests, which is to create something like shell/template configurations like database.yml.template and then copy that file and configure it for my environment as database.yml. Then I can .gitignore those new files.

If you want to do it without modifying how the files exist in repo, then:

git update-index --assume-unchanged [filename]

Will make git ignore changes to that file, but you have to be conscious of doing it.

More information here: http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html

这篇关于正确的git过程来更改不应该提交的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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