Git Stash Pop-使用mergetool解决冲突 [英] Git Stash Pop - Resolve Conflicts with mergetool

查看:613
本文介绍了Git Stash Pop-使用mergetool解决冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以

我突然遇到了这个问题,因为它以史诗般的错误形式使我的应用程序无用,但是git stash pop(或应用)会自动处理合并冲突.这样做时,它将两个版本都添加到文件中,如下所示:

I've come across this suddenly, as it, in epic blundering form, rendered my application useless, but git stash pop (or apply) automatically handles the merge conflicts. When it does this, it adds both versions to the file like so:

<<<<<<< Updated [remote]
     Change from Remote
=======
     Change from Stash
>>>>>>> Stashed changes

一开始不知道这一点会花费我一些时间,因为那些添加的行使xml文件无效.

Not knowing this at first cost me some time, as those added lines invalidated the xml file.

所以,我想知道是否有一种方法可以强制git stash不自动合并而是保留冲突,以便可以使用git mergetool解决冲突,而不是要求我在编辑器中打开每个文件并在没有为合并冲突而设计的"工具的好处的情况下处理合并"过程.

So, i am wondering if there is a way to enforce git stash to not auto-merge but to leave the conflicts in place so they can be resolved with the git mergetool, instead of requiring me to open each file in the editor and handle the "merte" process without the benefit of the tool designed for merge conflicts.

谢谢 Jaeden"Sifo Dyas" al'Raec Ruiner

Thanks Jaeden "Sifo Dyas" al'Raec Ruiner

推荐答案

git stash apply所使用的合并过程(这是git stash pop的前半部分)与其他任何合并相同,但其影响仍然存在:

The merge process used by git stash apply—this is the first half of git stash pop—is the same as any other merge, in terms of effect left behind:

$ git status
On branch master
nothing to commit, working tree clean
$ git log --all --decorate --oneline --graph
* f9a96c0 (HEAD -> master) conflicting changes for stash
| *   069a595 (refs/stash) WIP on master: 6fee57d add file "file"
| |\  
|/ /  
| * c466c42 index on master: 6fee57d add file "file"
|/  
* 6fee57d add file "file"
* 2353af8 initial

这时,无论我运行git stash apply还是git stash pop,都会遇到合并冲突,然后过程停止(不执行git stash pop的后半部分):

At this point, regardless of whether I run git stash apply or git stash pop, I get a merge conflict and then the process stops (does not do the second half of git stash pop):

$ git stash apply
Auto-merging file
CONFLICT (content): Merge conflict in file
$ git reset --hard HEAD
HEAD is now at f9a96c0 conflicting changes for stash
$ git stash pop
Auto-merging file
CONFLICT (content): Merge conflict in file
$ git stash list
stash@{0}: WIP on master: 6fee57d add file "file"

现在索引中的内容是未合并状态,同时显示文件file的所有三个副本:

What's in the index now is the unmerged state, with all three copies of file file present:

$ git ls-files --stage
100644 239c0dc4252320079890fff28cd408eb825776f5 0   README
100644 2983120c0897fea017d8398b5ffdc5e3ef0e17ad 1   file
100644 27b6da381575999c9ba975e9df9ba6caa45e3165 2   file
100644 080f90d42698e258e3efa8059c78ebfd5fdd7bd8 3   file

git mergetool足够高兴地在此时运行:

and git mergetool is happy enough to run at this point:

$ git mergetool 
[snip configuration complaint - I never use git mergetool
 so it is not configured]
Merging:
file

Normal merge conflict for 'file':
  {local}: modified file
  {remote}: modified file
Hit return to start merge resolution tool (bc): 

所以,我想知道是否有一种方法可以强制执行git stash而不是自动合并,而是将冲突留在原地...

So, i am wondering if there is a way to enforce git stash to not auto-merge but to leave the conflicts in place ...

文件的所有三个版本此时都存在于索引中.其中只有两个,--ours(通常与HEAD提交版本相同)和--theirs(在这种情况下为隐式提交版本),具有方便的git checkout命令语法,但是您可以提取合并基本版本,也使用:<number>:path语法.运行git mergetool会为您做到这一点-在运行配置的合并工具之前,先提取基本,左侧/本地/ours和右侧/远程/theirs版本.

All three versions of the file are present in the index at this point. Only two of them, --ours (usually the same as the HEAD commit version) and --theirs (the stashed-commit version, in this case), have convenient git checkout command syntax, but you can extract the merge base version too, using the :<number>:path syntax. Running git mergetool does that for you—extracts the base, left-side/local/ours, and right-side/remote/theirs versions—just before running your configured merge tool.

因此,我不确定您的问题是什么.

Hence, I'm not really sure what your question was.

这篇关于Git Stash Pop-使用mergetool解决冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆