首页 > 解决方案 > 忽略的文件显示为未跟踪

问题描述

当我将项目移动到存储库中的一个文件夹以保持一切井井有条时,整个问题就开始了。我想将令牌保留在 git 范围之外

我有一个.gitgnore如下:

bot/__pycache__/*
bot/token
bot/staging_token
*.pyc

由此我假设不应该跟踪 token 和 staging_token 。尽管如此, git status 显示:

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    bot/staging_token
    bot/token

我已经完成了git rm -r --cached .,然后git add .。之后,两个令牌仍被添加到暂存区。

为了对其进行测试,我还将 bot/* 添加到.gitgnore并重复git rm -r --cached .. 输出:

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    .gitgnore
    deleted:    Dockerfile
    deleted:    bot/main.py
    deleted:    bot/portfolio.py
    deleted:    bot/reply_messages.py
    deleted:    bot/requirements.txt
    deleted:    bot/telegram_commands.txt
    deleted:    bot/telegram_interface.py
    deleted:    bot/ticker.py
    deleted:    bot/yfinance.py
    deleted:    readme.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .gitgnore
    Dockerfile
    bot/
    readme.md

和 git add .. 这是输出:

On branch master
Your branch is ahead of 'origin/master' by 1 commit.
       (use "git push" to publish your local commits)

Changes to be committed:
        (use "git reset HEAD <file>..." to unstage)

    modified:   .gitgnore
    new file:   bot/staging_token
    new file:   bot/token

我应该怎么做才能使被忽略的文件不被跟踪?

标签: git

解决方案


您的输出将文件名显示为.gitgnore. 它必须是.gitignore


推荐阅读