Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git pull 时出现 Found a swap file by the name ".git/.MERGE_MSG.swp" 的问题 #127

Open
lovelmh13 opened this issue Jul 26, 2021 · 0 comments

Comments

@lovelmh13
Copy link
Owner

场景

当我们 pull 代码时,可能会出现这个问题:

E325: ATTENTION
Found a swap file by the name ".git/.MERGE_MSG.swp"
owned by: work dated: Mon May 17 11:51:29 2021
file name: ~work/oxp_works/.git/MERGE_MSG
modified: no
user name: work host name: yz-higo-fe-fex05.lehe.com
process ID: 6276 (still running)
While opening file ".git/MERGE_MSG"
dated: Mon May 17 12:23:09 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 .git/MERGE_MSG"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".git/.MERGE_MSG.swp"
to avoid this message.

再点击一下就会出现:

Merge branch 'master' of ...

这个是因为 git pull 是 fetch+Merge 的结合,本地可能有需要合并的东西(即使没有真的代码冲突)。

原因:

两种情况会出现这这种问题:

1.如果远程分支超前于本地分支,并且本地也没有commit操作,此时pull会采用’fast-forward’模式,该模式不会产生合并节点,也即不产生"Merge branch ‘master’ of …"信息。

2.如果本地有commit提交,此时若存在冲突,pull拉取代码时远程和本地会出现分叉,会进行分支合并,就会产生"Merge branch ‘master’ of …"信息。

解决方法:

自动合并:使用 git pull --rebase 来拉取代码

or

手动合并一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant