.gitignore 不会忽略文件

发布于 2024-09-04 14:43:36 字数 720 浏览 2 评论 0原文

我的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

情绪失控 2024-09-11 14:43:36

我遇到了同样的问题:我想要每个存储库有不同的 .htaccess 文件,但我不能,因为 htaccess 文件已添加到存储库。它现在正在工作,我可以更改任何版本的任何 .htaccess 文件,而无需 git 推送它们。马克说得对,“你需要先删除它,然后才能忽略它。这可以使用 git rm 来完成”。

我按以下顺序进行:

  • 在某处备份您的 .htaccess 文件
  • 使用 git rm .htaccess 删除 .htaccess 文件
  • 提交此更改(.htaccess 删除)
  • 推送它(git Push)

这显然会删除您的 .htaccess 文件

  • ,然后编辑 .gitignore 并添加 / .htaccess
  • 提交,然后推送它,
  • 通过恢复以前的备份重新创建 .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:

  • backup your .htaccess file somewhere
  • remove .htaccess file using git rm .htaccess
  • commit this change (.htaccess deletion)
  • push it (git push)

this will obviously remove your .htaccess file

  • then edit .gitignore and add /.htaccess
  • commit then push it
  • recreate your .htaccess file by restoring your previous backup

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

时光礼记 2024-09-11 14:43:36

这里提到的任何错误步骤之后,我的git仍然跟踪.htaccess,这有帮助:

git update-index --assume-unchanged .htaccess

要恢复:

git update-index --no-assume-unchanged .htaccess

after anybug's steps noted here my git still kept track of .htaccess and this helped:

git update-index --assume-unchanged .htaccess

To revert back:

git update-index --no-assume-unchanged .htaccess
不喜欢何必死缠烂打 2024-09-11 14:43:36

由于您希望:

  • .htaccess 保留在 Git 存储库中(无 git rm),其中
  • 包含本地敏感数据,因此

使用 过滤器驱动程序,它将:

  • .htaccess
  • 在结账阶段,使用私有数据完成 提交阶段清除 .htaccess 中的所有敏感数据

content filter driver

然后您可以对加密文件,您的涂抹脚本将:

  • 是唯一一个可以解密的文件
  • ,用于完成经典(和推/拉).htaccess 文件。

您可以在不推送的特殊分支中对加密的敏感数据进行版本控制。
即使您确实以某种方式推送了该文件,损害也将是有限的,因为只有您的工作站拥有解密该文件所需的私钥。

Since you want to:

  • keep .htaccess in the Git repo (no git rm)
  • have local sensitive data in it

use a filter driver which will:

  • during the checkout phase, complete the .htaccess with private data
  • during the commit phase clean the .htaccess from all sensitive data

content filter driver

you can then version an encrypted file that your smudge script will:

  • be the only one to decrypt
  • use in order to complete the classic (and pushed/pulled) .htaccess file.

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.

总以为 2024-09-11 14:43:36

假设以下是 .gitignore 文件的内容。这里,.htaccess 位于项目的根目录中。

/.htaccess
application/config/config.php
application/config/database.php

让我们运行以下命令来忽略 .htaccessconfig.phpdatabase.php 文件。

[email protected]:work-dir$ git update-index --assume-unchanged .htaccess
[email protected]:work-dir$ git update-index --assume-unchanged application/config/config.php
[email protected]:work-dir$ git update-index --assume-unchanged application/config/database.php

如果您想再次开始跟踪:

[email protected]:work-dir$ git update-index --no-assume-unchanged path/to/file

例如

[email protected]:work-dir$ git update-index --no-assume-unchanged .htaccess

Suppose the below is the content of .gitignore file. Here, .htaccess is in the project's root directory.

/.htaccess
application/config/config.php
application/config/database.php

Let's run the below command to ignore the .htaccess, config.php and database.php files.

[email protected]:work-dir$ git update-index --assume-unchanged .htaccess
[email protected]:work-dir$ git update-index --assume-unchanged application/config/config.php
[email protected]:work-dir$ git update-index --assume-unchanged application/config/database.php

If you want to start tracking it again:

[email protected]:work-dir$ git update-index --no-assume-unchanged path/to/file

e.g.

[email protected]:work-dir$ git update-index --no-assume-unchanged .htaccess
轻拂→两袖风尘 2024-09-11 14:43:36

看来 .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

夏夜暖风 2024-09-11 14:43:36

忽略 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 added your files and are now trying to ignore them.

盗琴音 2024-09-11 14:43:36

我一直这样做。我从我的存储库中的配置文件开始,然后决定我不希望它们在那里。

您可以使用以下命令从存储库中删除某些内容

git rm --cached <<filename>>

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

git rm --cached <<filename>>
七秒鱼° 2024-09-11 14:43:36

这件事困扰了我好几天。 .htaccess 文件已处于版本控制之下并且已被修改。

This one bugged me for days. The .htaccess file is already under version control and has been modified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文