删除未跟踪的文件将被标记为已删除

时间:2018-06-14 10:44:17

标签: git git-clean

我在git repo中有以下状态:

git status

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

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

    docs/file1.docx

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

所以我会做一个:

git clean -fdx 

之后,git status将显示以下内容:

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

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

    deleted:    docs/file1.docx

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

如果我删除未跟踪的文件怎么会被标记为已删除?

1 个答案:

答案 0 :(得分:0)

我不知道是什么原因造成的,但是有时我会进入相同的状态。发生这种情况时,我可以通过运行:

git clean --force

(或git clean -f),它会删除未跟踪的文件,但不是会导致git将它们标记为已删除。

有关更多信息,请运行git help clean。它具有其他各种标志和功能,您可能会发现有帮助。