我希望git show <commit>
和git diff <commit>^ <commit>
显示给定提交中发生的所有更改,但我看到他们的更改列表有所不同。 (见下面的例子。)那么对它们的功能有正确的理解是什么?
是的,我已经阅读了手册页
git show
For commits it shows the log message and textual diff. It also presents the
merge commit in a special format as produced by git diff-tree --cc.
git diff
git diff [--options] <commit> <commit> [--] [<path>...]
This is to view the changes between two arbitrary <commit>.
$ MY_COMMIT=7c95d118c9837f801f4e314732c593e25feba3b1
git show
及其输出:$ git show --name-only $MY_COMMIT
commit 7c95d118c9837f801f4e314732c593e25feba3b1
Merge: 5f308b4 9ef9bd7
Author: Me <quinesquines@gmail.com>
Date: Thu Apr 23 14:14:58 2015 -0700
Merge branch 'develop' of github.com:pic-development/dataraptor into develop
Conflicts:
app/controllers/application_controller.rb
app/controllers/usage/staff_assignment_controller.rb
app/views/crm/connections/_show.html.erb
app/views/crm/task_builders/_task_builders.html.haml
spec/controllers/contacts_controller_spec.rb
spec/controllers/crm/connections_controller_spec.rb
app/controllers/application_controller.rb
app/controllers/usage/staff_assignment_controller.rb
app/views/crm/connections/_show.html.erb
git diff
及其输出:$ git diff --name-only $MY_COMMIT^ $MY_COMMIT
app/assets/javascripts/application/quoting/ng-new-quote.js
app/assets/stylesheets/application-layout.css.scss
app/assets/stylesheets/application.css
app/controllers/application_controller.rb
app/controllers/crm/connections_controller.rb
app/controllers/usage/staff_assignment_controller.rb
app/models/crm/connection.rb
app/models/usage/permissions.rb
app/views/crm/connections/_show.html.erb
app/views/crm/task_builders/_task_builder.html.erb
app/views/layouts/application.html.erb
app/views/marketing/campaigns/_index.html.haml
app/views/marketing/campaigns/_task_builders.html.haml
app/views/shared/tab/_agency_management.html.erb
app/views/shared/tab/_contracts.html.erb
app/views/shared/tab/_help.html.erb
app/views/shared/tab/_marketing.html.erb
app/views/shared/tab/_my_account.html.erb
app/views/shared/tab/_reporting.html.erb
app/views/shared/tab/_sales_tools.html.erb
app/views/shared/tab/_system_management.html.erb
app/views/shared/tab/_underwriting_suitability.html.erb
app/views/usage/agent_field_sets/_new_submission_option.html.erb
app/views/usage/users/_personal.html.erb
vendor/assets/stylesheets/bootstrap-combined.min.css
vendor/assets/stylesheets/bootstrap.css
vendor/assets/stylesheets/pixel-admin.css
vendor/assets/stylesheets/themes.css
答案 0 :(得分:2)
您正在显示合并提交的差异。
考虑一个带有以下提交的示例(F是最新的提交),并且您正在执行git show F
和git diff F^ F
(实际上是git diff C F
)。
A--B--C--F
\ /
D----E
git show
仅显示合并提交中已更改的文件。这可能包括具有手动修复的合并冲突的文件。它将不显示在其中一个合并分支中修改的文件(如B,C或D,E),并且可以干净地合并。引用手册页(强调我的):
对于提交[git show]显示日志消息和文本差异。它还以git diff-tree --cc。
生成的特殊格式显示合并提交[git diff-tree --cc]进一步压缩补丁输出省略不感兴趣的帅哥,其中父母的内容只有两个变体,合并结果选择其中一个没有修改强>
git diff <commit>^ <commit>
显示合并提交的第一个父级和合并提交的区别。由于合并提交包含来自第一个和第二个父级的所有更改,因此您有效地显示了整个分支的差异(因此在我的示例中,提交D和E)已合并提交。
答案 1 :(得分:0)
默认情况下,对于合并提交,git show
生成(如文档所述)a&#34;合并差异&#34;。直接使用git diff
只涉及三个或更多提交中的两个提交 1 会产生常规(非组合)差异。
documentation on combined diffs有点被埋没了,出于某种原因这句话:
请注意,组合差异仅列出从所有修改过的文件 父母。
完全在另一部分。并且,此处链接的部分指的是git diff
当您无法告诉git diff
同时查看所有合并的父母时(您必须使用git diff-tree
或git show
为此。)
1 合并提交是至少有两个父母的提交,因此这里提交的三个或更多提交是您git show
的提交,即其第一个父提交({ {1}}),它的第二个父级($MY_COMMIT^1
),以及任何其他父级($MY_COMMIT^2
等,用于&#34;章鱼合并&#34;)。