我正在研究测试脚本并尝试重现git合并冲突AU(未合并,由我们添加)
我一直想着AA,或UU,我尝试的一切。例如:
产生UU冲突,这不是我正在寻找的。 p>
生成AU冲突需要执行哪些步骤?
答案 0 :(得分:1)
想出来。这是事件的顺序:
运行git status -s
时,冲突会以“AU”结束答案 1 :(得分:1)
要在Pavel Chernikov's answer上展开一点,这里有一个shell脚本 1 ,它会产生正确的冲突。请注意,此特定重命名/删除冲突由AU
宣布为git status --short
,因为重命名的文件保留在索引和工作树中,但在阶段2中(即--ours
索引槽。
#! /bin/sh
SELF=$(basename "$0")
if git rev-parse --show-toplevel 2>/dev/null; then
echo 'this must be run in a temporary dir that is not a git tree'
exit 1
fi
files="$(ls -A)"
if [ "$files" != "" -a "$files" != "$SELF" ]; then
echo "this temporary dir has too many files"
echo "(should be empty or contain only \"$SELF\")"
exit 1
fi
echo 'initializing new Git repository'
git init >/dev/null || exit 1
echo 'demonstrate rename vs delete conflict' > README
cat > file1 << 'end'
here is a file
it is named file1
at least it is, initially
it has a bunch of contents
so that it's clear that this is the same file
even after we rename it.
end
echo "$SELF" > .gitignore
git add README file1 .gitignore
git commit -q -m initial
git checkout -q -b b1
git rm -q file1
git commit -q -m 'remove file1'
git checkout -q -b b2 master
git mv file1 file2
git commit -q -m 'rename file1 to file2'
echo 'the next merge will have a rename/delete conflict:'
git merge b1 | sed 's/^/ /' 2>&1
echo
echo 'however, git status --short shows AU:'
git status --short
# clean up
rm -rf .git README file2 .gitignore
运行脚本会产生:
initializing new Git repository
the next merge will have a rename/delete conflict:
CONFLICT (rename/delete): file2 deleted in b1 and renamed in HEAD. Version HEAD of file2 left in tree.
Automatic merge failed; fix conflicts and then commit the result.
however, git status --short shows AU:
AU file2
我们可以交换合并,以便在保留--ours
时删除--theirs
(以便保留的索引条目位于插槽3中)。这只是在分支b1
中开始,然后合并其提示由b2
标识的提交
git checkout -q b1
git merge b2
现在抱怨:
CONFLICT (rename/delete): file2 deleted in HEAD and renamed in b2. Version b2 of file2 left in tree.
并且git status --short
输出已交换AU
以建议广告位更改:
UA file2
1 这仅使用sh
个功能,但也适用于bash
。