我可以强制 Git 忽略我的配置或“站点本地”吗?提交时的数据?
现在我正在开发一个带有 config.py
文件的项目,该文件在 Git 存储库中包含如下行:
debug = False
database = ''
但我的本地工作副本在其位置上有这些行:
debug = True
database = 'sqlite:///site.db'
这些行几乎从来没有更改,但每次提交时我仍然被迫手动添加每个更改,因此我可以从索引中省略对 config.py 的更改。理想情况下,我想找到一种方法来告诉 Git 忽略对这些行或整个文件的更改,但仍将它们包含在存储库中,这样我的 git status 屏幕就会干净,并且我可以使用 git commit -a 。
如果这是不可能的,是否有推荐的工作流程来避免存储库和工作副本之间的这种不匹配?
Right now I'm working on a project with a config.py
file, which in the Git repo, contains lines like this:
debug = False
database = ''
But my local working copy has these lines in their place:
debug = True
database = 'sqlite:///site.db'
These lines hardly ever change, but still every time I commit I'm forced to add each change manually, so I can omit the changes to config.py
from the index. Ideally, I'd like to find a way to tell Git to ignore changes to those lines or the entire file, but still include them in the repo, so my git status
screen would be clean, and I could use git commit -a
.
If that's not possible, is there a recommended workflow to avoid this mismatch between the repo and the working copy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 git update-index --assume-unchanged config.py 。这将使
git
不会注意到文件的任何更改,直到您签出另一个分支或以其他方式重建索引。不幸的是,如果您需要对必须在存储库(而不是.gitignore
)中跟踪的文件进行长期更改,那么这是最好的解决方案。更好的解决方案是根本不跟踪该文件,并将其放入存储库特定的
.git/info/excludes
或.gitignore
文件中。Try
git update-index --assume-unchanged config.py
. This will makegit
not notice any changes to the file until you check out another branch or otherwise rebuild the index. This is, unfortunately, the best solution if you need a long-term set of changes to a file which must be tracked in the repository (and not in.gitignore
).A better solution is to make the file not be tracked at all, and put it in your repository-specific
.git/info/excludes
or.gitignore
file.