git 如何解决git合并错误“交换文件.MERGE_MSG.swp已经存在”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41284031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:42:47  来源:igfitidea点击:

How to solve git merge error "Swap file .MERGE_MSG.swp already exists"

gitgithubgithub-for-mac

提问by Tigerotic

When I pull:

当我拉:

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!

When I push:

当我推:

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.

Please help :C Idk what to do. I can't push or pull. I tried pretty much everything I could think of. I also tried: git merge --abort. The thing is when I do that, I can't seem to find my conflict that I should resolve.

请帮助 :C 我知道该怎么做。我不能推也不能拉。我尝试了几乎所有我能想到的。我也试过:git merge --abort。问题是当我这样做时,我似乎找不到我应该解决的冲突。

回答by quetzalcoatl

It's a message from VIM which apparently you are using as the text editor in git. Have you tried reading and following these two (1) (2) points? One of them will be probably true, and will let you solve this issue.

这是来自 VIM 的一条消息,显然您将其用作 git 中的文本编辑器。您是否尝试阅读并遵循这两 (1) (2) 点?其中之一可能是正确的,并且可以让您解决这个问题。

First of all, check that MERGE_MSGfile (not MERGE_MSG.swp), and see if it exists and what's inside. Most likely it's trash or a temporary file that can be safely deleted. Judging from the name, it's probably the file name used as a temporary text editing area for merge commit messages.

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

Then, since you use VIM, when VIM starts, it tries to create a swap file for its own internal needs. The error message says it's ~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp. Often, you can simply delete such swap files, especially if they are old or unexpected. However, if recently some merge-commit-message-editing session has crashed and if you had a lot of creative text you don't want to lose - then don't delete it and recoverthat swap instead, as described in (2) in the error message.

然后,由于您使用 VIM,当 VIM 启动时,它会尝试为自己的内部需要创建一个交换文件。错误消息说它是~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp. 通常,您可以简单地删除此类交换文件,特别是如果它们是旧的或意外的。但是,如果最近某个合并提交消息编辑会话崩溃了,并且如果您有很多不想丢失的创意文本,则不要删除它并恢复该交换,如 (2) 中所述在错误消息中。

However, since you don't know what is going on and you haven't said anything about losing some text you wrote, and since it's probably just a MERGE_MSG that was auto-generated anyways, I suppose you can:

但是,由于您不知道发生了什么并且您没有说过丢失一些您写的文本,并且因为它可能只是一个自动生成的 MERGE_MSG,我想您可以:

git merge --abort
rm ~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp

and try what you were doing once again.

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

Also, it's good to check the hint mentioned in (1) in error message. Check with psor whatever else for any open VIM sessions that could be currently editing that MERGE_MSG. If you spot any, then, well, get to them and either finish editing, or make them quit (escape, :q!, enter) (vim will cleanup swaps on quitting), or terminate them (kill them, but then you need to remove swap files manually).

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

回答by guru

I have same issue with my terminal,I quit the terminal and it works for me!!!

我的终端有同样的问题,我退出了终端,它对我有用!!!

回答by Galvarado

Had the same issue and fixed it quitting the terminal and committing again.

有同样的问题并修复它退出终端并再次提交。