如何解决git merge错误"​​交换文件.MERGE_MSG.swp已经存在"

Tig*_*tic 24 git github github-for-mac

当我拉:

E325: ATTENTION
Found a swap file by the name "~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp"
          owned by: username   dated: Wed Dec 14 12:28:45 2016
         file name: ~username/Documents/Sites/recipegenerator/.git/MERGE_MSG
          modified: YES
         user name: username   host name: Users-MacBook-Pro.local
        process ID: 33747
While opening file "/Users/larsvanurk/Documents/Sites/recipegenerator/.git/MERGE_MSG"
             dated: Thu Dec 22 14:06:17 2016
      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 /Users/username/Documents/Sites/recipegenerator/.git/MERGE_MSG"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/Users/username/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp"
    to avoid this message.

Swap file "~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp" already exists!
Run Code Online (Sandbox Code Playgroud)

我推的时候:

To  https://github.com/nickname/recipegenerator.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/nickname/recipegenerator.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)

请帮忙:C Idk做什么.我不能推或拉.我尝试了几乎所有我能想到的东西.我也尝试过:git merge --abort.事情是,当我这样做时,我似乎无法找到我应该解决的冲突.

que*_*atl 34

这是来自VIM的消息,显然你在git中用作文本编辑器.您是否尝试过阅读并遵循这两(1)(2)分?其中一个可能是真的,并会让你解决这个问题.

首先,检查该MERGE_MSG文件(不是MERGE_MSG.swp),看看它是否存在以及内部是什么.很可能它是垃圾或可以安全删除的临时文件.从名称来看,它可能是用作合并提交消息的临时文本编辑区域的文件名.

然后,由于您使用VIM,当VIM启动时,它会尝试为自己的内部需求创建交换文件.错误消息说明了~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp.通常,您可以简单地删除这些交换文件,特别是如果它们是旧的或意外的.但是,如果最近一些merge-commit-message-editing会话崩溃了,如果你有很多创意文本你不想丢失 - 那么就不要删除它并恢复那个交换,如(2)中所述在错误消息中.

但是,既然你不知道发生了什么,你还没有说丢失你写的一些文字,因为它可能只是一个自动生成的MERGE_MSG,我想你可以:

git merge --abort
rm ~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp
Run Code Online (Sandbox Code Playgroud)

并再次尝试你正在做的事情.

此外,最好在错误消息中检查(1)中提到的提示.检查ps当前正在编辑MERGE_MSG的任何打开的VIM会话或其他任何内容.如果你发现任何,那么,好吧,去找他们,或者完成编辑,或者让他们退出(逃避,:q!,输入)(vim将在退出时清理交换),或者终止他们(杀死他们,但是你需要手动删除交换文件).


Moh*_*hod 6

您需要通过以下方式中止当前提交

git merge --abort
Run Code Online (Sandbox Code Playgroud)

那么您需要删除合并消息文件。

转到项目目录并通过以下命令删除文件

rm .git/.MERGE_MSG.swp
Run Code Online (Sandbox Code Playgroud)

您也可以使用以下单个命令来完成

git merge --abort && rm .git/.MERGE_MSG.swp
Run Code Online (Sandbox Code Playgroud)

  • 这与我 4 岁时的答案有何不同?尽管如此,它肯定比我的更简洁:) (2认同)