Git 2.36提出了一个更简单的命令:
(branch_A_tag)
|
--X--A--B--C--D--F (master)
\ / \ /
\ / \ /
G--H--I--J (branch A)
vonc@vclp MINGW64 ~/git/tests/branchOrigin (branch_A)
git log -1 --decorate --oneline \
$(git rev-parse \
$(git rev-list --exclude-first-parent-only ^main branch_A| tail -1)^ \
)
80e8436 (tag: branch_A_tag) A - Work in branch main
^main branch_A给出的是J—I—H—G
-1得到G
git rev-parse G^给你它的第一个父:A或branch_A_tag
使用测试脚本:
mkdir branchOrigin
cd branchOrigin
git init
git commit --allow-empty -m "X - Work in branch main"
git commit --allow-empty -m "A - Work in branch main"
git tag branch_A_tag -m "Tag branch point of branch_A"
git commit --allow-empty -m "B - Work in branch main"
git switch -c branch_A branch_A_tag
git commit --allow-empty -m "G - Work in branch_A"
git switch main
git merge branch_A -m "C - Merge branch_A into branch main"
git switch branch_A
git commit --allow-empty -m "H - Work in branch_A"
git merge main -m "I - Merge main into branch_A"
git switch main
git commit --allow-empty -m "D - Work in branch main"
git merge branch_A -m "F - Merge branch_A into branch main"
git switch branch_A
git commit --allow-empty -m "J - Work in branch_A branch"
这就给了你:
vonc@vclp MINGW64 ~/git/tests/branchOrigin (branch_A)
$ git log --oneline --decorate --graph --branches --all
* a55a87e (HEAD -> branch_A) J - Work in branch_A branch
| * 3769cc8 (main) F - Merge branch_A into branch main
| |\
| |/
|/|
* | 1b29fa5 I - Merge main into branch_A
|\ \
* | | e7accbd H - Work in branch_A
| | * 87a62f4 D - Work in branch main
| |/
| * 7bc79c5 C - Merge branch_A into branch main
| |\
| |/
|/|
* | 0f28c9f G - Work in branch_A
| * e897627 B - Work in branch main
|/
* 80e8436 (tag: branch_A_tag) A - Work in branch main
* 5cad19b X - Work in branch main
这是:
(branch_A_tag)
|
--X--A--B--C--D--F (master)
\ / \ /
\ / \ /
G--H--I--J (branch A)
在Git 2.36 (Q2 2022)中,“Git log”(man)和朋友们学习了一个选项——exclude-first-parent-only只沿着第一个父链向下传播UNINTERESTING位,就像——first-parent选项只显示在第一个父链上缺乏UNINTERESTING位的提交一样。
参见Jerry Zhang (Jerry -skydio)提交的9d505b7 (11 Jan 2022)。
(由Junio C Hamano—gitster—在commit 708cbef中合并,2022年2月17日)
Git-rev-list: add——exclude-first-parent-only标志
署名:Jerry Zhang
It is useful to know when a branch first diverged in history from some integration branch in order to be able to enumerate the user's local changes.
However, these local changes can include arbitrary merges, so it is necessary to ignore this merge structure when finding the divergence point.
In order to do this, teach the "rev-list" family to accept "--exclude-first-parent-only", which restricts the traversal of excluded commits to only follow first parent links.
-A-----E-F-G--main
\ / /
B-C-D--topic
In this example, the goal is to return the set {B, C, D} which represents a topic branch that has been merged into main branch.
git rev-list topic ^main(man) will end up returning no commits since excluding main will end up traversing the commits on topic as well.
git rev-list --exclude-first-parent-only topic ^main(man) however will return {B, C, D} as desired.
Add docs for the new flag, and clarify the doc for --first-parent to indicate that it applies to traversing the set of included commits only.
Rev-list-options现在包括在它的手册页:
——“首席家长
当找到要包含的提交时,只遵循第一个
父节点在看到合并提交时提交。
这个选项
能给一个更好的概述时,查看的演变
一个特定的主题分支,因为合并到一个主题中
分支倾向于只调整到更新的上游
时不时地,这个选项可以让你忽略
个人的承诺被带入你的历史
一个合并。
Rev-list-options现在包括在它的手册页:
——exclude-first-parent-only
当发现提交排除(使用'{插入符号}')时,只跟随
第一个父节点在看到合并提交时提交。
这可用于查找主题分支中的更改集
从它与远分支的分歧点开始
任意的合并可以是有效的主题分支更改。