什么是 git 边界提交

问题描述 投票:0回答:3

git log
命令有一个
--boundary
选项,这会导致程序

输出排除的边界提交。

但是什么是边界提交?我什么时候可以将它们包含在输出中?

git
3个回答
14
投票

边界提交是限制修订范围但不属于该范围的提交。例如,修订范围

HEAD~3..HEAD
由 3 个提交(
HEAD~2
HEAD~1
HEAD
)组成,并且提交
HEAD~3
作为其边界提交。

更正式地说,git 通过从指定范围的末尾提交开始(在前面的示例中为

HEAD

)并通过父链接获取其他提交来处理修订范围。它在不满足选择标准的提交处停止(因此应该被排除) - 这些是边界提交。

图示:

$ mkdir test $ cd test $ git init Initialized empty Git repository in ~/playground/git/test/.git/ $ touch a $ git add a $ for i in {1..5}; do echo $i >> a; git commit -m "Commit #$i" a; done [master (root-commit) bf958f1] Commit #1 1 file changed, 1 insertion(+) create mode 100644 a [master 3721a8b] Commit #2 1 file changed, 1 insertion(+) [master d69efcc] Commit #3 1 file changed, 1 insertion(+) [master 72cd21d] Commit #4 1 file changed, 1 insertion(+) [master 17ae9c3] Commit #5 1 file changed, 1 insertion(+) $ git log --oneline 17ae9c3 Commit #5 72cd21d Commit #4 d69efcc Commit #3 3721a8b Commit #2 bf958f1 Commit #1 $ git log --oneline HEAD~3.. 17ae9c3 Commit #5 72cd21d Commit #4 d69efcc Commit #3 $ git log --oneline HEAD~3.. --boundary 17ae9c3 Commit #5 72cd21d Commit #4 d69efcc Commit #3 - 3721a8b Commit #2 <-- This is the boundary commit HEAD~3 that would not be included in the output had the '--boundary' option NOT been provided
    

4
投票

--boundary

  
  

--boundary

参数用于显示提交(父修订)的上下文。 

边界提交是指不属于执行命令的“框架”的提交。 (--自、提交范围等)

例如,如果您使用

–since=3.weeks

这样的参数,则
三周之前的提交将被视为boundary commits
。通常 
boundary
 提交标记有 
-
 

您可以在上面的屏幕截图中看到最后一次提交在第二个日志中“消失”了。这是由于

--boundary

 标志

您可以看到提交之前有一个

o

 符号,而不是常规提交中的 
*


1
投票
我有一个具体的例子来说明何时我想看到边界提交:

比较两个不同分支中的提交的一种方法是查看两个分支的对称差异:

# for example: see the commits of a branch with respect to the commits in its upstream: git log --graph --oneline <branch>...<branch>@{u}
上述命令的一个问题是:由于“对称差异”不包括两个分支之间的共同基础,因此输出是线性提交序列:

* (branch) local commit 3 * local commit 2 * local commit 1 * (origin/branch) remote commit 2 * remote commit 1
一个更好的(恕我直言)视图是绘制相同的图形,同时包含公共合并基础。这可以通过添加 

--boundary

 :
来完成

$ git log --boundary --graph --oneline <branch>...<branch>@{u} * (branch) local commit 3 * local commit 2 * local commit 1 | * (origin/branch) remote commit 2 | * remote commit 1 |/ o last common commit
您还可能在其他一些视图中拥有更好的图表,例如分支分叉的视图提交:

# will not show the history of 'master', # but will show the commit on 'master' from which each branch starts git log --graph --oneline --boundary ^master feature1 feature2 feature2
    
© www.soinside.com 2019 - 2024. All rights reserved.