无法结帐分支或删除有问题的文件

问题描述 投票:2回答:3

我的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 intellij-idea git-merge git-checkout
3个回答
4
投票

将以下内容添加到.gitignore

.idea

并删除此目录

git rm -r .idea

然后提交更改。


1
投票

查看手册

git clean --help

0
投票

第一次运行

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
© www.soinside.com 2019 - 2024. All rights reserved.