1

Given branch-a and git rebase origin/master branch-a, sometimes you get conflicts in a file.

CONFLICT (content): Merge conflict in .../file.txt

Given that before the rebase there were no conflicts (by definition), then conflicts can only have occurred b/c one or more commits to .../file.txt.

During the conflict resolution process, I can't figure out a way to easily show "commits from origin/master that affected .../file.txt" so that I can more confidently integrate those changes.

---A---B---[C]---D
    \             \
     E---[F]---G   E'--[C/F']--G'

ABCD is mainline development. EFG is my local branch development. Commit C caused a conflict in file/commit F during my local rebase onto D.

Given a detached HEAD or "rebasing" state, when I do git log -3 file.txt it doesn't seem to show me what I want to see, which is WHAT was the diff (ie: commit C) which caused the conflict I'm trying to resolve now when applying commit F.

How can I get a list of commits which only affect a particular file and are from the range ABCD... not including my commits in EFG or the currently active --rebase?

4

2 回答 2

1

你应该得到你需要的输出:

git log --patch --full-history A..D -- file.txt

( --patchor -p) 标志可能是您要查找的主要内容:它显示记录的每个提交的差异。

--full-history标志可防止 Git 通过忽略基于工作树当前状态的提交来简化历史记录。根据您的具体情况,这可能不是必需的。

A..D输出限制为提交A(不包括)和提交D(包括)之间的提交。这可能是一种更可靠的限制提交的方法,而不是-3,假设你有 refsA并且D方便。实际上,您总是可以方便地使用两个 refs,因为这D是您的主线分支的尖端,您可以A通过以下方式获得:

git merge-base <mainline> <local>

一个具体的例子:

假设主线分支是master,另一个分支是feature

git rebase master feature
# conflicts occur
git log --patch --full-history $(git merge-base master feature)..master -- file.txt

为了节省时间,您还可以设置别名:

git config --global alias.conflict-commits "! git log --patch --full-history $(git merge-base $1 $2)..$1 -- $3"

然后将其用作:

git conflict-commits master feature file.txt
于 2016-10-19T23:23:13.703 回答
0

您可以选择log命令的来源为origin/master

git log origin/master -3 file.txt
于 2016-10-19T23:23:41.133 回答