带有和不带有< path>的git log之间的区别仅当< path>被改变了? [英] Difference between git log with and without <path> when only <path> was changed?

查看:121
本文介绍了带有和不带有< path>的git log之间的区别仅当< path>被改变了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有两个合并的分支,并且每个分支都独立进行了相同的更改时,该文件的git日志仅显示这些实例之一,而整个repo的git日志则显示两个实例.为什么会这样?

When I have two branches that have been merged, and in each one the same change was made independently, the git log of that file shows only one of these instances, while the git log of the entire repo shows both. Why is that?

这是我创建更改的地方:

Here is where I created a change:

example:/test # git branch
* master
example:/test # cat > testfile 
aoeu
example:/test # git add -u; git commit -m "Add aoeu"
[master 34513b3] Add aoeu
 1 file changed, 1 insertion(+)

然后我在备用分支上进行了相同的更改:

Then I put the same change on the alternate branch:

example:/test # git checkout -b alternate HEAD^
Switched to a new branch 'alternate'
example:/test # git cherry-pick -n master
example:/test # git commit
[alternate 52efabd] Add aoeu
 1 file changed, 1 insertion(+)

现在,我合并两个分支,并查看结果.为什么在第一个"git log"的输出中看不到commit 34513b3?

Now I merge the two branches, and look at the results. Why don't I see commit 34513b3 in the output of the first "git log"?

example:/test # git merge master
Merge made by the 'recursive' strategy.
example:/test # git log --oneline --graph testfile
* 52efabd Add aoeu
* d7a9a91 Initial commit
example:/test # git log --oneline --graph
*   838c5fd Merge branch 'master' into alternate
|\  
| * 34513b3 Add aoeu
* | 52efabd Add aoeu
|/  
* d7a9a91 Initial commit

当然,我在哪个分支上都没关系:

Of course, it doesn't matter which branch I'm on:

example:/test # git checkout master
Switched to branch 'master'
example:/test # git merge alternate
Updating 34513b3..838c5fd
Fast-forward
example:/test # git log --oneline --graph testfile
* 52efabd Add aoeu
* d7a9a91 Initial commit

git如何确定这些提交中的哪一个是正式的?为什么我们要看文件范围还是完整的回购范围呢?如何获得我期望的行为,即显示所有属于HEAD祖先并且正在接触受影响文件的提交?

How does git decide which of these commits is the official one? And why does it matter whether we look with file scope or full repo scope? How can I get the behaviour I expect, i.e. to show all commits which are ancestors of HEAD and which are touching the affected file?

推荐答案

答案被埋在

The answer is buried in the git rev-list documentation (this same text is included in the git log documentation but since virtually everything uses rev-list, I think it's the right place to remember as your general lookup location):

简化历史记录
有时您只对历史的某些部分感兴趣,例如 提交修改特定的< path>.但是有两个部分 历史简化,一部分是选择提交,另一部分是选择提交 是如何做到的,因为有多种策略可以简化 历史.

History Simplification
Sometimes you are only interested in parts of the history, for example the commits modifying a particular <path>. But there are two parts of History Simplification, one part is selecting the commits and the other is how to do it, as there are various strategies to simplify the history.

以下选项选择要显示的提交:

The following options select the commits to be shown:

[snip]

以下选项会影响简化的方式:

The following options affect the way the simplification is performed:

--full-history
与默认模式相同,但不修剪某些历史记录

--full-history
Same as the default mode, but does not prune some history

(大概)想要--full-history模式时,您正在使用默认模式.请注意,当您使用< paths>引入历史选择的符号:这就是为什么不需要不需要--full-history的原因.

You're using the default mode when you (presumably) want --full-history mode. Note that history simplification gets activated when you use the <paths> notation to introduce history selection: that's why you don't need --full-history without it.

这篇关于带有和不带有&lt; path&gt;的git log之间的区别仅当&lt; path&gt;被改变了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆