最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]git stash pop出错:needs merge unable to refresh index

Git crifan 20291浏览 0评论

之前git stash pop后,出现文件冲突CONFLICT:

licrifandeMacBook-Pro:iOS-Client crifan$ git stash pop
Auto-merging JianDao/MyViewController.swift
CONFLICT (content): Merge conflict in JianDao/MyViewController.swift
licrifandeMacBook-Pro:iOS-Client crifan$ git stash
JianDao/MyViewController.swift: needs merge
JianDao/MyViewController.swift: needs merge
JianDao/MyViewController.swift: unmerged (b810e289979d1441ef86cec76f7cf5824bdbf2c8)
JianDao/MyViewController.swift: unmerged (bba0e193d34a6b8693e41a3d722c76646e7798e0)
JianDao/MyViewController.swift: unmerged (208eff046bbef7dfaac7ceaeff57438c80ac3b1b)
fatal: git-write-tree: error building trees
Cannot save the current index state
licrifandeMacBook-Pro:iOS-Client crifan$ git pull
error: Pull is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use ‘git add/rm <file>’
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
licrifandeMacBook-Pro:iOS-Client crifan$ git stash pop
JianDao/MyViewController.swift: needs merge
unable to refresh index
licrifandeMacBook-Pro:iOS-Client crifan$ 

然后此处,其实已经把有冲突的文件,解决冲突,修改好了。

但是却不知道如何继续操作,才能正常提交修改。

好像需要先commit(到本地master?)

看看右击文件:

还是先去搜索:

git stash pop needs merge unable to refresh index

Git stash pop- needs merge, unable to refresh index – Stack Overflow

licrifandeMacBook-Pro:iOS-Client crifan$ git status
On branch master
Your branch is up-to-date with ‘origin/master’.
Changes to be committed:
  (use "git reset HEAD <file>…" to unstage)
modified:   JianDao/ContactUtility.swift
modified:   JianDao/JianDao.xcodeproj/project.pbxproj
modified:   JianDao/JianDao/Constants.swift
modified:   JianDao/JianDao/Info.plist
Unmerged paths:
  (use "git reset HEAD <file>…" to unstage)
  (use "git add <file>…" to mark resolution)
both modified:   JianDao/MyViewController.swift
Changes not staged for commit:
  (use "git add <file>…" to update what will be committed)
  (use "git checkout — <file>…" to discard changes in working directory)
modified:   JianDao/JianDao/Constants.swift
licrifandeMacBook-Pro:iOS-Client crifan$

git stash unable to refresh, how to pop only some files – Stack Overflow

Brewokr: Git stash pop- needs merge, unable to refresh index

Fix merge conflicts in Git? – Stack Overflow

好像需要去commit对应的,原先那个冲突的,现在已经修复了的文件,

然后估计就可以了。

其实人家都提示了:

use "git add <file>…" to mark resolution

所以去:

licrifandeMacBook-Pro:iOS-Client crifan$ git add JianDao/MyViewController.swift

但是接着:

licrifandeMacBook-Pro:iOS-Client crifan$ git stash pop
Auto-merging JianDao/MyViewController.swift

却导致了:

之前改好了的冲突的文件,结果又被恢复冲突了。。。

现在想要:

恢复刚才

git stash pop

之前的状态

[未解决]恢复git stash pop之前的状态

还是手动改了一遍,解决了语法错误。

再去git add进去:

licrifandeMacBook-Pro:iOS-Client crifan$ git add JianDao/MyViewController.swift
licrifandeMacBook-Pro:iOS-Client crifan$ git status
On branch master
Your branch is up-to-date with ‘origin/master’.
Changes to be committed:
  (use "git reset HEAD <file>…" to unstage)
modified:   JianDao/ContactUtility.swift
modified:   JianDao/JianDao.xcodeproj/project.pbxproj
modified:   JianDao/JianDao/Constants.swift
modified:   JianDao/JianDao/Info.plist
modified:   JianDao/MyViewController.swift
Changes not staged for commit:
  (use "git add <file>…" to update what will be committed)
  (use "git checkout — <file>…" to discard changes in working directory)
modified:   JianDao/JianDao/Constants.swift
licrifandeMacBook-Pro:iOS-Client crifan$

看看文件右键,也不是之前的Mark Selected Files as Resolved,已经修复了:

此时再去提交,发现该文件从C==Conflict变成M=Modified了:

-》

意味着可以正常提交修改了。

[总结]

在已经解决了有冲突Conflict之后,再去

git stash pop却出错

needs merge unable to refresh index

的解决办法是:

标记该文件为已解决冲突

方法1:

Xcode-》右击该文件-》Mark Selected Files as Resolved-》即可

举例:

方法2:

去终端命令行中:

git add yourConflictedHasResolvedFile

即可。

之后即可正常提交修改了:

不过由于忘了git pull,导致推送更新到服务器失败:

[已解决]git push出错:The local repository is out of date

转载请注明:在路上 » [已解决]git stash pop出错:needs merge unable to refresh index

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.187 seconds, using 22.07MB memory