如何解决所有合并冲突,以支持刚刚弹出的存储? [英] How to resolve all merge conflicts in favor of the just-popped stash?
问题描述
git stash pop
时,会得到 CONFLICT
消息(由于自动合并失败尝试)。 是否有一种快速告诉 git
来解决所有冲突的方法有人赞成刚才弹出的存储?
编辑:我只写了下面的脚本来测试提出的两个替代方案。它在目录 / tmp / $ 1
中创建一个全新的git仓库,并且
- 创建文件的第一个版本并提交它; >对文件进行一些更改并存储文件;
- 对文件进行其他更改(包括冲突和非冲突更改)并提交这些更改;最后
- 弹出存储
- 对文件进行其他更改(包括冲突和非冲突更改)并提交这些更改;最后
<
cd
s; 这为比较两种建议的方法提供了舞台。这里是脚本:
shopt -s expand_aliases
别名gcommit ='git commit -q --allow-empty- message -m'
alias gmerge ='git merge -q --no-edit'
TESTDIR = / tmp / $ 1
rm -rf$ TESTDIR
mkdir -p$ TESTDIR
cd$ TESTDIR
git init -q
touch chiasmus.txt
git add。 &安培;&安培; gcommit
cat<< EOF> chiasmus.txt
询问
什么
...
EOF
gcommit -a
猫< ;< EOF> chiasmus.txt
询问
不是
什么
您的国家可以为您做什么
...
EOF
git stash -q
cat<< EOF> chiasmus.txt
报价:
询问
什么
你可以为你的国家做什么
...
jfk
EOF
gcommit -a
git stash pop -q
然后我跑了
%bash gittest.sh checkout
%bash gittest.sh合并
%cd / tmp / checkout
%git checkout - 他们的$(git diff --name-only --diff-filter = U)
%cd / tmp / merge
%git reset -q --hard
%git merge -q --no-edit --squash -Xtheirs存储
自动合并chiasmus.txt
壁球提交 - 不更新HEAD
自动合并进行得很顺利;在按要求提交之前停止
%diff /tmp/{checkout,merge}/chiasmus.txt
0a1
> quote:
5a7
> jfk
因此,看起来checkout选项确实会丢失无冲突的更改。但事实上,这个选项更贴近我后面的内容,也就是说,让 git pop
与我期望的更接近:将我返回到哪里当时我运行 git stash
,句点。没有自动合并等等(IOW,我的问题,如问,真的没有准确地反映我以后的事情。就好像 meagar
只要自己合并,而不是隐藏流行音乐。隐藏提交名为隐藏
。
git merge --squash -Xtheirs藏匿
Suppose that upon running git stash pop
, one gets a CONFLICT
message (resulting from a failed auto-merging attempt).
Is there a quick way to tell git
to resolve all conflicts in favor of the stash that was just popped?
EDIT: I just wrote the following script to test the two alternatives proposed. It
- creates a fresh git repo in the directory
/tmp/$1
, andcd
s to it; - creates a first version of a file and commits it;
- makes some changes to the file and stashes the file;
- makes other changes to the file (including both conflicting and non-conflicting changes), and commits these changes; and finally
- pops the stash
This sets the stage for comparing the two proposed methods. Here's the script:
shopt -s expand_aliases
alias gcommit='git commit -q --allow-empty-message -m ""'
alias gmerge='git merge -q --no-edit'
TESTDIR=/tmp/$1
rm -rf "$TESTDIR"
mkdir -p "$TESTDIR"
cd "$TESTDIR"
git init -q
touch chiasmus.txt
git add . && gcommit
cat <<EOF > chiasmus.txt
ask
what
...
EOF
gcommit -a
cat <<EOF > chiasmus.txt
ask
not
what
your country can do for you
...
EOF
git stash -q
cat <<EOF > chiasmus.txt
quote:
ask
what
you can do for your country
...
jfk
EOF
gcommit -a
git stash pop -q
Then I ran
% bash gittest.sh checkout
% bash gittest.sh merge
% cd /tmp/checkout
% git checkout --theirs $(git diff --name-only --diff-filter=U)
% cd /tmp/merge
% git reset -q --hard
% git merge -q --no-edit --squash -Xtheirs stash
Auto-merging chiasmus.txt
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
% diff /tmp/{checkout,merge}/chiasmus.txt
0a1
> quote:
5a7
> jfk
Therefore, it looks like the "checkout" option does lose the non-conflicting changes. As it happens, though, this option more closely matches what I was really after, namely, have git pop
behave more closely to what I expect it to do: return me to where I was when I ran git stash
, period. No auto-merge, etc. (IOW, my question, as asked, really did not accurately reflect what I was after. It's as if meagar read my mind somehow.)
Just do the merge yourself, instead of the stash pop. The stash commit's named stash
.
git merge --squash -Xtheirs stash
这篇关于如何解决所有合并冲突,以支持刚刚弹出的存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!