无法签出分支或删除有问题的文件

Cannot checkout branch or remove problematic files

我的 Java 项目有 2 个分支:master 和 refactor。我已经完成了重构工作,所以现在想 checkout master 并将重构合并到 master 中。在进行重构时,我还向 .gitignore 添加了一些文件(其中一个是 .idea),现在我得到:

[michal@michal-pc MCleaner]$ git checkout master
error: The following untracked working tree files would be overwritten by checkout:
.idea/description.html
.idea/misc.xml
.idea/modules.xml
.idea/project-template.xml
.idea/vcs.xml
Please move or remove them before you switch branches.
Aborting

我看了很多帖子,但没有任何效果。如何在不访问 master 分支的情况下删除这些文件?有没有办法解决这个问题?如果可以请提供cmd命令,我还是git的新手。

这是 git status 的输出:

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

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

nothing added to commit but untracked files present (use "git add" to track)

查看

的手册
git clean --help

将以下内容添加到 .gitignore

.idea

并删除这个目录

git rm -r .idea

然后提交更改。

第一个运行

get checkout <branch_name>

结果会像下面这样

error: The following untracked working tree files would be overwritten by checkout:
        .idea/codeStyles/Project.xml
        .idea/codeStyles/codeStyleConfig.xml
        .idea/workspace.xml
Please move or remove them before you switch branches.
Aborting

如果您不介意丢失这些文件中的任何数据(它们将被覆盖),请继续运行

get checkout <branch_name> --force