【问题标题】:delete file named "~" and unstage from git从 git 中删除名为“~”的文件并取消暂存
【发布时间】:2021-11-18 00:51:33
【问题描述】:

我不确定这是怎么发生的(也许我输入了命令行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:   ~

【问题讨论】:

  • 我想我记得前段时间有人问过他的? 目录……确实很可怕。

标签: git macos unix


【解决方案1】:

使用反斜杠转义

rm \~

或者,您可以使用单引号来避免 shell 解释(而不是转义 shell 解释)

rm '~'

由于提交是暂存的,您还需要在合并之前清除它,方法是再次adding 删除的文件(因此它的缺席被合并到暂存的提交中)或reset-ing 删除的文件(这可能是因为你使用了git add -a)

git add \~

虽然您的担心是实际的,但也不要担心,rm 不会删除目录,只会删除文件,而不提供一些标志(-d-r-R..)

【讨论】:

  • 啊哈,成功了,谢谢!
  • @prototype 会想要git rm 它,或者git add 在使用普通rm 后删除。 :-)
  • 没错,让我补充一点!
猜你喜欢
  • 2012-03-24
  • 2011-05-14
  • 1970-01-01
  • 2021-01-19
  • 2019-11-09
  • 2023-03-17
  • 2013-11-12
  • 1970-01-01
  • 2010-12-03
相关资源
最近更新 更多