Git:如何提交手动删除的文件?

ron*_*nie 77 git github

在我的git存储库中,我将文件(rm)移动到另一个文件夹后手动删除.我并没有把所有的改变都交给我的回购,但现在我做了git status .

ronnie@ronnie:/home/github/Vimfiles/Vim$ git status .
# On branch master
# 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:    plugin/dwm.vim
#
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)

现在,我应该如何提交,以便dwm.vim从我的远程仓库中的插件文件夹中删除.我知道我必须使用,git add && git commit但我没有文件提交/添加,因为/plugin/dwm.vim已经删除.

s.m*_*.m. 93

我想答案就在这里.

不过,如果你使用它会更好git rm.

  • 我知道我应该使用`git rm`但是`rm`是我的习惯所以有时我只是忘了使用`git rm`. (6认同)
  • 可以在 `rm` 已经删除文件后使用 `git rm`。它只是更新本地存储库。 (5认同)
  • 答案是`git add -u`、`git commit -a` 或`git add -A`?-1 表示混乱。 (4认同)

xda*_*azz 73

使用git add -A,这将包括已删除的文件.

注意:git rm用于某些文件.

  • 如果某人只是想删除单个文件,我认为建议使用`git add -A`并不是一个好主意,因为这也会(a)对已经跟踪的文件进行所有修改并且(b)阶段未跟踪和未签名的文件.您可能希望更新您的答案,并提供相关警告. (35认同)

Kac*_*che 28

它在输出中说git status:

#   (use "git add/rm <file>..." to update what will be committed)
Run Code Online (Sandbox Code Playgroud)

所以只做:

git rm <filename>
Run Code Online (Sandbox Code Playgroud)

  • 但这很令人困惑:“使用“git add/rm”——它是什么?在这种情况下,两者之间有什么区别? (5认同)