再现git合并冲突:AU

时间:2017-04-29 19:29:10

标签: git git-merge git-merge-conflict

我正在研究测试脚本并尝试重现git合并冲突AU(未合并,由我们添加)

我一直想着AA,或UU,我尝试的一切。例如:

  • 创建回购
  • 创建/暂存/提交测试文件
  • 创建源分支,更新/阶段/提交测试文件
  • Checkout master,delete / stage / commit test file
  • 创建目标分支,添加/暂存/提交测试文件
  • 尝试将源分支合并到目标分支

产生UU冲突,这不是我正在寻找的。

生成AU冲突需要执行哪些步骤?

2 个答案:

答案 0 :(得分:1)

想出来。这是事件的顺序:

  • 在master
  • 上创建/ stage / commit file1
  • 从主
  • 创建源分支
  • 在源分支上删除/暂存/提交
  • 从主人
  • 结帐目标分支
  • 将file1重命名/暂存/提交到file2
  • 将源分支合并为主

运行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