当将 foo
重新定位到 master
时遇到冲突时,是否有办法以编程方式确定哪个提交在 master
上导致冲突?
要手动执行此操作,我基本上会找到冲突的行, checkout master
,运行 git Blame
,然后查看 merge 基础后哪些提交更改了这些行。
有没有一种简单的方法可以以编程方式完成该过程?
问题是否与以下内容重复
与这些其他问题不同,我想知道目标分支上的哪些提交导致了冲突,而不是我正在 rebase 的分支上的提交。
最佳答案
假设您可以中止 rebase 来进行此测试,我将通过在 master 上临时创建一个新分支,尝试将其 rebase 到 foo 来实现它,并提取在该操作期间首先发生冲突的提交。
#!/bin/bash
# Make these command line parameters if you want
dest=master
source=foo
# Find the conflict commit
git checkout $dest
tmp_branch=$(mktemp -u | sed 's/.*\///') # Not strictly safe, I know, but it works
git checkout -b $tmp_branch
if git rebase $source; then
conflict_commit=None
else
conflict_commit=$(git am --show-current-patch | head -1 | sed 's/ *commit *//')
git rebase --abort
fi
git checkout $source
git branch -D $tmp_branch
# Use $conflict_commit as needed
echo Conflict at "$conflict_commit"
关于git - 确定目标分支中的哪个提交导致了冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67566615/