所以,
我突然遇到了这个问题,因为它以史诗般的错误形式使我的应用程序变得毫无用处,但 git stash pop (或 apply)会自动处理 merge 冲突。当它执行此操作时,会将两个版本添加到文件中,如下所示:
<<<<<<< Updated [remote]
Change from Remote
=======
Change from Stash
>>>>>>> Stashed changes
一开始不知道这一点花了我一些时间,因为这些添加的行使 xml 文件失效。
所以,我想知道是否有一种方法可以强制 git stash 不自动 merge ,而是将冲突保留在适当的位置,以便可以使用 git mergetool 解决它们,而不是要求我在编辑器中打开每个文件并在没有为 merge 冲突设计的工具的情况下处理“merte”过程。
谢谢 Jaeden "Sifo Dyas"al'Raec Ruiner
最佳答案
git stash apply
使用的 merge 过程—这是git stash pop
的前半部分——就留下的效果而言,与任何其他 merge 相同:
$ 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
,我遇到 merge 冲突,然后进程停止(不执行 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"
现在索引中的内容是未 merge 状态,包含文件 file
的所有三个副本目前:
$ git ls-files --stage
100644 239c0dc4252320079890fff28cd408eb825776f5 0 README
100644 2983120c0897fea017d8398b5ffdc5e3ef0e17ad 1 file
100644 27b6da381575999c9ba975e9df9ba6caa45e3165 2 file
100644 080f90d42698e258e3efa8059c78ebfd5fdd7bd8 3 file
和git mergetool
此时很高兴可以运行:
$ 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):
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
(在本例中为 stash 提交版本),有方便的 git checkout
命令语法,但您也可以使用 :<number>:path
提取 merge 基础版本句法。运行git mergetool
为你做这件事——提取基数,左侧/本地/ours
,以及右侧/远程/theirs
版本 - 在运行配置的 merge 工具之前。
因此,我不太确定您的问题是什么。
关于Git Stash Pop - 使用 mergetool 解决冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46330531/