我主要对activerecord/lib/active_record/associations.rb
两个提交中与文件相关的差异感兴趣。
正如您在此处看到的,我将这两个提交都放在一个集合中:
[284] pry(main)> commits2.first.sha
=> "c6e01f5b60c4864f0e92149d1e81077519f503d5"
[285] pry(main)> commits2.second.sha
=> "581f12b7b18a6e5205bfabb814f6e9997bf92be8"
请注意,这两个 SHA 都对应于我在上面发布的链接中的 SHA,并且两者都是唯一的(即彼此不同)。
然而,当我获得每个提交的内容时,特别是与我感兴趣的路径相关的内容时,我得到两个提交的相同结果。
pry(main)> repo
=> "rails/rails"
pry(main)> path
=> "activerecord/lib/active_record/associations.rb"
c1 = client.contents(repo, path: path, sha: commits2.first.sha)
pry(main)> c1.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
然后我对第二次提交做同样的事情,我得到以下信息:
pry(main)> c2 = client.contents(repo, path: path, sha: commits2.second.sha)
pry(main)> c2.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
请注意,SHA 是相同的。
两者的内容c1
也c2
相同。你可以在下面看到它们:
pry(main)> c1
=> {:name=>"associations.rb",
:path=>"activerecord/lib/active_record/associations.rb",
:sha=>"3729e22e6423348aa9282cd17b49c09793ca3a6f",
:size=>94931,
:url=>
"https://api.github.com/repos/rails/rails/contents/activerecord/lib/active_record/associations.rb?ref=master",
:html_url=>
"https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb",
:git_url=>
"https://api.github.com/repos/rails/rails/git/blobs/3729e22e6423348aa9282cd17b49c09793ca3a6f",
:download_url=>
"https://raw.githubusercontent.com/rails/rails/master/activerecord/lib/active_record/associations.rb",
:type=>"file",
:content=>
"cmVxdWlyZSAnYWN0aXZlX3N1cHBvcnQvY29yZV9leHQvZW51bWVyYWJsZScK\ncmVxdWlyZSAnYWN0aXZlX3N1cHBvcnQvY29yZV9leHQvc3RyaW5nL2NvbnZl\ncnNpb25zJwpyZXF1aXJlICdhY3RpdmVfc3VwcG9ydC9jb3JlX2V4dC9tb2R1\nbGUvcmVtb3ZlX21ldGhvZCcKcmVxdWlyZSAnYWN0aXZlX3JlY29yZC9lcnJv\ncnMnCgptb2R1bGUgQWN0aXZlUmVjb3JkCiAgY2xhc3MgQXNzb2NpYXRpb25O\nb3RGb3VuZEVycm9yIDwgQ29uZmlndXJhdGlvbkVycm9yICM6bm9kb2M6CiAg\nICBkZWYgaW5pdGlhbGl6ZShyZWNvcmQgPSBua
为了简洁,我截断了content
。
为什么会这样?如果您手动查看我在顶部发布的两个链接,然后向下滚动到associations.rb
代码,您会看到两者都对该文件进行了更改。
那么为什么content
for BOTH 提交是相同的呢?
好困惑:|
编辑 1
为了回应蒂姆的评论,也许提交是精心挑选的,而且它们确实是相同的,我又做了两个提交(这个和这个),但结果似乎是一样的:
[299] pry(main)> commits2.third.html_url
=> "https://github.com/rails/rails/commit/1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace"
[300] pry(main)> commits2.third.sha
=> "1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace"
[301] pry(main)> commits2.fourth.html_url
=> "https://github.com/rails/rails/commit/3c01e01ded4e8e87d48e844881c88f6e47cebdf0"
[302] pry(main)> commits2.fourth.sha
=> "3c01e01ded4e8e87d48e844881c88f6e47cebdf0"
pry(main)> c3 = client.contents(repo, path: path, sha: commits2.third.sha)
pry(main)> c3.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
pry(main)> c4 = client.contents(repo, path: path, sha: commits2.fourth.sha)
pry(main)> c4.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"