.gitignore 不会忽略文件
我的 .gitignore 文件被忽略,而应忽略的文件仍然可见。
user@host ~/workdir % git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .htaccess
# modified: application/controllers/statistics.php
#
no changes added to commit (use "git add" and/or "git commit -a")
user@host ~/workdir % cat .gitignore
.htaccess
application/config/config.php
application/config/database.php
user@host ~/workdir %
这些文件处于版本控制中,但对于合理的更改,我不想推送。 git rm ... 不是一个选项,因为文件应该处于版本控制中(以及文件中的其他设置)。我只是不想将我的更改推送到此文件上。
My .gitignore file gets ignored and the files which should be ignored are still visible.
user@host ~/workdir % git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .htaccess
# modified: application/controllers/statistics.php
#
no changes added to commit (use "git add" and/or "git commit -a")
user@host ~/workdir % cat .gitignore
.htaccess
application/config/config.php
application/config/database.php
user@host ~/workdir %
The files are in version control, but with sensible changes I dont want to push. git rm ... is not an option because the files should be in version controll (with other settings in the files). I just dont want to push my changes on this files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我遇到了同样的问题:我想要每个存储库有不同的 .htaccess 文件,但我不能,因为 htaccess 文件已添加到存储库。它现在正在工作,我可以更改任何版本的任何 .htaccess 文件,而无需 git 推送它们。马克说得对,“你需要先删除它,然后才能忽略它。这可以使用 git rm 来完成”。
我按以下顺序进行:
这显然会删除您的 .htaccess 文件
,然后就完成了:您对 .htaccess 所做的任何更改都不会再推送。困难的部分是遵循步骤顺序...
希望这一点很清楚
i had same problem: i wanted different .htaccess file per repository then i couldn't because htaccess file had already been added to repository. It's working now, i can change any of the .htaccess file from any version without getting git pushing them. Marc is right when he says "You need to remove it first, before it can be ignored. This can be done using git rm".
i proceeded in this order:
this will obviously remove your .htaccess file
then you're done: whatever changes you make into .htaccess won't be pushed anymore. The hard part is following steps order...
hope this is clear
在这里提到的任何错误步骤之后,我的git仍然跟踪.htaccess,这有帮助:
要恢复:
after anybug's steps noted here my git still kept track of .htaccess and this helped:
To revert back:
由于您希望:
.htaccess
保留在 Git 存储库中(无git rm
),其中使用 过滤器驱动程序,它将:
.htaccess
.htaccess
中的所有敏感数据然后您可以对加密文件,您的涂抹脚本将:
您可以在不推送的特殊分支中对加密的敏感数据进行版本控制。
即使您确实以某种方式推送了该文件,损害也将是有限的,因为只有您的工作站拥有解密该文件所需的私钥。
Since you want to:
.htaccess
in the Git repo (nogit rm
)use a filter driver which will:
.htaccess
with private data.htaccess
from all sensitive datayou can then version an encrypted file that your smudge script will:
You can version that encrypted sensible data in a special branch you won't push.
Even if you did push that file somehow, the damage would be limited, since only your workstation has the private key needed to decrypt said file.
假设以下是 .gitignore 文件的内容。这里,
.htaccess
位于项目的根目录中。让我们运行以下命令来忽略
.htaccess
、config.php
和database.php
文件。如果您想再次开始跟踪:
例如
Suppose the below is the content of
.gitignore
file. Here,.htaccess
is in the project's root directory.Let's run the below command to ignore the
.htaccess
,config.php
anddatabase.php
files.If you want to start tracking it again:
e.g.
看来
.htaccess
文件已经被添加到版本控制中。您需要先将其删除,然后才能将其忽略。这可以使用 git rm 来完成It seems that the
.htaccess
file has already been added to the version control. You need to remove it first, before it can be ignored. This can be done using git rm忽略 git 中的文件并不意味着您不会推送它们。这意味着您不会对它们进行版本控制。如果您不想推送,我建议您创建一个本地分支,其中包含本地计算机的内容,然后将必要的更改合并到您将推送到远程的分支。
我认为您已经
添加
了您的文件,现在正试图忽略它们。Ignoring files in git doesn't mean that you won't push them. It means that you won't version control them. If you don't want to push then, I suggest you create a local branch which will contain stuff for the local machine and then merge necessary changes to a branch which you'll push to remote.
I think you've already
add
ed your files and are now trying to ignore them.我一直这样做。我从我的存储库中的配置文件开始,然后决定我不希望它们在那里。
您可以使用以下命令从存储库中删除某些内容
I do this all the time. I start with configuration files in my repo then decide that I don't want them in there.
You can remove something from your repo by using
这件事困扰了我好几天。
.htaccess
文件已处于版本控制之下并且已被修改。This one bugged me for days. The
.htaccess
file is already under version control and has been modified.