如何 .gitignore 并删除已提交的文件而不影响其他工作副本?
我有一个裸存储库和两个工作副本 - 一个在我的计算机上,另一个在服务器上。
事实证明,我必须 .gitignore
某个特定于每台机器的文件。我们将其命名为“settings.py
”。该文件已经提交。
我确实将 'settings.py
' 放入 .gitignore 中以忽略它。当我现在更改机器上的文件时,git status 仍然告诉我
modified: settings.py
,我发现我必须像这样删除 settings.py:
git rm --cached settings.py
然后 git add .
,然后是 git commit
。
但是,当我现在将其推送到裸存储库并将其拉到服务器上的工作副本时,settings.py
会在那里被删除 - 这很糟糕,因为我必须保留这个特定的设置。 py
.
我想我可以制作 settings.py
的副本,并在删除后将其放回原处,但我觉得必须有更好的方法来做到这一点。
I have a bare repository and two working copies - one on my machine, the other on the server.
It turned out that I have to .gitignore
a certain file that has to be specific for every machine. Let's call it 'settings.py
'. This file is already committed.
I did put 'settings.py
' in .gitignore to ignore it. When I now change the file on my machine git status still tells me
modified: settings.py
I figured out that I have to remove settings.py like this:
git rm --cached settings.py
Then git add .
, followed by git commit
.
But when I now push this to the bare repo and pull it to the working copy on the server, settings.py
is deleted there - which is bad because I have to keep this specific settings.py
.
I figured that I just could make a copy of settings.py
and put it back in once it is deleted, but I feel like there has to be a better way of doing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以告诉 git 完全忽略对跟踪文件的更改,而不必删除它们。使用此命令:
然后,如果您想稍后跟踪该文件:
You can tell git to completely ignore changes to tracked files without having to remove them. Use this command:
Then if you want to track the file later:
您是否愿意将 settings.py 永久删除(本地和远程),并且:
setting_remote
文件,setting_local
文件(即具有本地特定设置)settings.py
文件。这样,
settings.py
就保持“私有”(非版本化)。但每个环境的具体值都是版本化的,每个值都在自己的文件中设置,没有任何合并问题。Could you rather keep settings.py deleted permanently (both locally and on remote), and:
setting_remote
file for the remote sidesetting_local
file for the local side (ie with local specific settings)settings.py
file on checkout.That way,
settings.py
is kept "private" (non-versioned). But the specific values for each environment are versioned, each set in its own file, without any merging issue.