git - 确定目标分支中的哪个提交导致了冲突

标签 git

当将 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/

相关文章:

eclipse - Git 提交不可能。没有暂存文件

java - 如何适应多种编码风格? (git 与 IDE)

克隆存储库的 git 状态显示文件已删除

git - 使用空提交消息重新定位 git 历史记录

Git rebase : do I have to have a clean working directory first?

git - 如何让我的 'Detached HEAD' 提交回到 master

git - 修复不完整的.git目录

git - 自安装 Big Sur 以来,无法再通过 HTTPS git 克隆大型存储库

git - 如何将Git提交移动到另一个分支并在原始分支中删除它们?

eclipse - .git 本地存储库是否必须包含在本地工作目录中?