我不确定这是如何发生的(也许我输入了命令行vi ~ /extra/space.txt
?),但现在有一个名为~
的文件已准备好提交。我不想将其添加到 git,并且我犹豫是否要尝试 rm ~
在考虑可能的副作用之前。
$ git status
On branch master
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
modified: apples.js
modified: app/berries.js
modified: app/views/pears.js
new file: app/views/lemons.js
modified: public/stylesheets/oranges.css
new file: ~
最佳答案
使用反斜杠进行转义
rm \~
或者,您可以使用单引号来避免 shell 解释(而不是转义 shell 解释)
rm '~'
由于提交是暂存的,您还需要在 merge 之前通过再次添加
删除的文件来清除它(因此它的缺失会 merge 到暂存的提交中)或重置
-ing 删除的文件(这可能是因为您使用了 git add -a
)
git add \~
虽然您的担心是实际的,但也不必担心,rm
不会删除目录,只会删除文件,而不提供一些标志(-d
, -r
, -R
..)
关于git - 删除名为 "~"的文件并从 git 取消暂存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69320056/