问题描述
当我有两个合并的分支,并且每个分支都独立进行了相同的更改时,该文件的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?
推荐答案
答案被埋在 git rev-list
文档( git log
文档,但是由于几乎所有内容都使用rev-list
,因此我认为这是记住的一般查找位置的正确位置):
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):
以下选项选择要显示的提交:
The following options select the commits to be shown:
[snip]
-
--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.
这篇关于带有和不带有< path>的git log之间的区别仅当< path>被改变了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!