【问题标题】:Git how to not include specific file(s) to commitGit如何不包含要提交的特定文件
【发布时间】:2015-04-30 20:55:17
【问题描述】:

我试图不包含一些要提交的文件。例如,我不希望将以下文件中的任何更改包含在提交中:

bootstrap/start.php

所以我将它们包含在 .gitignore 中,如下所示:

/bootstrap/compiled.php
/bootstrap/start.php
/vendor
composer.phar
composer.lock
.env.local.php
.env.php
.DS_Store
Thumbs.db.idea
.idea/
/public/dbase
/public/user_images
/app/config/lenovo

但是当我运行git status 时,我仍然收到这条消息:

On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   .gitignore
    modified:   bootstrap/start.php

no changes added to commit (use "git add" and/or "git commit -a")

如何做到这一点?谢谢

【问题讨论】:

    标签: git gitignore git-commit


    【解决方案1】:

    bootstrap/start.php 已被 git 跟踪。

    来自 gitignore 文档“gitignore 文件指定了 Git 应忽略的故意未跟踪的文件。Git 已跟踪的文件不受影响;有关详细信息,请参阅下面的注释。”

    【讨论】:

    • 这是什么意思? bootstrap/start.php 中的任何更改是否仍会提交?
    • 这意味着您已经将 bootstrap/start.php 添加到 git 存储库并且 git 正在跟踪文件的更改。您可以通过命令git update-index --assume-unchanged bootstrap/start.php 告诉 git 停止忽略对跟踪文件的更改,然后您可以使用 git update-index --no-assume-unchanged bootstrap/start.php 重新开始跟踪这些更改
    • git update-index --assume-unchanged bootstrap/start.php 这个工作,如果我运行git status bootstrap/start.php 不再列出......谢谢先生:)。我不希望 git 跟踪的文件有任何变化,所以我不需要运行 git update-index --no-assume-unchanged bootstrap/start.php 对吗?
    • 是的...仅当您想在未来某个时间重新启用更改跟踪时才运行它
    【解决方案2】:

    试试这个。

    git update-index --assume-unchanged bootstrap/start.php
    

    【讨论】:

      猜你喜欢
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 2019-05-19
      • 2022-01-03
      • 2019-08-21
      • 2017-02-18
      • 2019-04-28
      相关资源
      最近更新 更多