显示影响不在功能分支中的文件的提交?
Show commits affecting a file that are not in a feature branch?
给定 branch-a
和 git rebase origin/master branch-a
,有时您会在文件中遇到冲突。
CONFLICT (content): Merge conflict in .../file.txt
假设在变基之前没有冲突(根据定义),那么冲突只能发生 b/c 一次或多次提交 .../file.txt
。
在解决冲突的过程中,我想不出一个方法来轻松显示"commits from origin/master that affected .../file.txt",以便我可以更自信地整合这些更改。
---A---B---[C]---D
\ \
E---[F]---G E'--[C/F']--G'
ABCD
是主线开发。 EFG
是我本地的分支开发。在我本地变基到 D
.
期间,提交 C
在 file/commit F
中引起了冲突
考虑到分离的 HEAD 或 "rebasing" 状态,当我执行 git log -3 file.txt
时,它似乎没有显示我想看到的内容,即 WHAT 是差异(即:提交 C
)导致我现在在应用提交 F
.
时试图解决的冲突
如何获取仅影响特定文件且范围 ABCD
... 不包括我在 EFG
或当前活动 [=25= 中的提交的列表]?
你应该得到你需要的输出:
git log --patch --full-history A..D -- file.txt
--patch
(或-p
)标志可能是您正在寻找的主要内容:它显示了记录的每个提交的差异。
--full-history
标志阻止Git 通过省略基于工作树当前状态的提交来简化历史。这可能不是必需的,具体取决于您的具体情况。
A..D
将输出限制为提交 A
(不包括)和提交 D
(包括)之间的提交。这可能是一种比 -3
更可靠的限制提交的方法,假设您手边有 A
和 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 ).. -- "
然后将其用作:
git conflict-commits master feature file.txt
您可以选择 log
命令的来源为 origin/master
:
git log origin/master -3 file.txt
给定 branch-a
和 git rebase origin/master branch-a
,有时您会在文件中遇到冲突。
CONFLICT (content): Merge conflict in .../file.txt
假设在变基之前没有冲突(根据定义),那么冲突只能发生 b/c 一次或多次提交 .../file.txt
。
在解决冲突的过程中,我想不出一个方法来轻松显示"commits from origin/master that affected .../file.txt",以便我可以更自信地整合这些更改。
---A---B---[C]---D
\ \
E---[F]---G E'--[C/F']--G'
ABCD
是主线开发。 EFG
是我本地的分支开发。在我本地变基到 D
.
C
在 file/commit F
中引起了冲突
考虑到分离的 HEAD 或 "rebasing" 状态,当我执行 git log -3 file.txt
时,它似乎没有显示我想看到的内容,即 WHAT 是差异(即:提交 C
)导致我现在在应用提交 F
.
如何获取仅影响特定文件且范围 ABCD
... 不包括我在 EFG
或当前活动 [=25= 中的提交的列表]?
你应该得到你需要的输出:
git log --patch --full-history A..D -- file.txt
--patch
(或-p
)标志可能是您正在寻找的主要内容:它显示了记录的每个提交的差异。
--full-history
标志阻止Git 通过省略基于工作树当前状态的提交来简化历史。这可能不是必需的,具体取决于您的具体情况。
A..D
将输出限制为提交 A
(不包括)和提交 D
(包括)之间的提交。这可能是一种比 -3
更可靠的限制提交的方法,假设您手边有 A
和 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 ).. -- "
然后将其用作:
git conflict-commits master feature file.txt
您可以选择 log
命令的来源为 origin/master
:
git log origin/master -3 file.txt