交换文件“.swp 文件地址”已存在

问题描述

我是 git 新手。我有一个文件,它的名字是:index.txt。 我写了 git add index.txt --patch 然后我想手动编辑它,但它显示了这个错误:


E325: ATTENTION
Found a swap file by the name "~/sample/.git/.addp-hunk-edit.diff.swp"
          owned by: Administrator   dated: Tue Apr 06 23:58:10 2021
         file name: ~Administrator/sample/.git/addp-hunk-edit.diff
          modified: YES
         user name: Administrator   host name: DESKTOP-CNVC9R0
        process ID: 1152 (STILL RUNNING)
While opening file "/c/Users/Administrator/sample/.git/addp-hunk-edit.diff"
             dated: Wed Apr 07 01:22:22 2021
      NEWER than swap file!

(1) Another program may be editing the same file.  If this is the case,be careful not to end up with two different instances of the same
    file when making changes.  Quit,or continue with caution.
(2) An edit session for this file crashed.
    If this is the case,use ":recover" or "vim -r /c/Users/Administrator/sample/.git/addp-hunk-edit.diff"
    to recover the changes (see ":help recovery").
    If you did this already,delete the swap file "/c/Users/Administrator/sample/.git/.addp-hunk-edit.diff.swp"
    to avoid this message.

Swap file "~/sample/.git/.addp-hunk-edit.diff.swp" already exists!
[O]pen Read-Only,(E)dit anyway,(R)ecover,(Q)uit,(A)bort:

enter image description here

谁能告诉我我该怎么办? 如果我必须删除 .swp,谁能帮我一步一步?

解决方法

它看起来像一个 vim swp 文件。我只想删除它。但为了安全起见,这里是重命名它的方法。首先确保 vim 没有运行。然后运行这个命令:

mv -i /c/Users/Administrator/sample/.git/.addp-hunk-edit.diff.swp /c/Users/Administrator/sample/.git/.addp-hunk-edit.diff.swp_disabled

-i 选项将提示您文件是否已具有新名称。我通常将 -i 选项与 mv(移动)、rm(移除)和 cp(复制)一起使用,除非我想用剪刀跑步:)

如果您在“sample”目录中,则命令可以缩短:

mv -i .git/.addp-hunk-edit.diff.swp .git/.addp-hunk-edit.diff.swp_disabled

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...