如何清除状态条目

时间:2012-08-14 13:18:46

标签: git github

我上传了一堆文件,但在提交到存储库之前删除了它们。当我做git status时,我看到了这一点:

# deleted: filename.fileext

我已经能够提交新的更改但这些已删除的文件仍然出现在状态检查中。有人可以解释原因吗?我如何摆脱它们?

2 个答案:

答案 0 :(得分:0)

git add -u
git commit -m "Deleted files manually"

答案 1 :(得分:0)

如果您使用rm命令删除文件,请运行git rm <file_path_to_be_removed>告诉git这些文件已被删除。

rm命令仅删除物理文件。然后你需要通知git。

kevin@kevin-dev:/tmp/git$ touch a.txt
kevin@kevin-dev:/tmp/git$ git add a.txt
kevin@kevin-dev:/tmp/git$ git commit -m"m"
[master (root-commit) 03f6743] m
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.txt
kevin@kevin-dev:/tmp/git$ git status 
# On branch master
nothing to commit (working directory clean)
kevin@kevin-dev:/tmp/git$ rm a.txt 
kevin@kevin-dev:/tmp/git$ git status 
# On branch master
# Changes not staged for commit:
#   (use "git add/rm ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#       deleted:    a.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
kevin@kevin-dev:/tmp/git$ git rm a.txt
rm 'a.txt'
kevin@kevin-dev:/tmp/git$ git status 
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       deleted:    a.txt
#
kevin@kevin-dev:/tmp/git$ 

拖曳deleted状态不同。第一个是未提交的更改提交:,第二个是要提交的更改: 所以,只需运行git commimt -m"Message",然后一切都很干净。