git 使用 github.com 查看文件的更改历史
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17888643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
View the change history of a file using github.com
提问by propstm
I've found this postabout using the command line, but is it possible to view the file change history of a single file in a repository on github.com?
我找到了这篇关于使用命令行的帖子,但是是否可以查看 github.com 上存储库中单个文件的文件更改历史记录?
An in-browser solution would help me to better illustrate changes to team members while in meetings.
浏览器内解决方案将帮助我在会议中更好地说明团队成员的变化。
采纳答案by Burhan Khalid
You can view the change history of a file by clicking on the history button, or by adding commits
to the URL of the file. Here is what it looks like for a file at the Homebrewrepository on GitHub:
您可以通过单击历史记录按钮或添加commits
到文件的 URL来查看文件的更改历史记录。以下是GitHub 上Homebrew存储库中文件的外观:
https://github.com/mxcl/homebrew/commits/master/SUPPORTERS.md
https://github.com/mxcl/homebrew/commits/master/SUPPORTERS.md
To get a line-by-line history, simply add the SHA-1string of the commit for which you want to see the diff to the URL after the word commit
, and then anchor it with the filename you are interested in. For the same file above:
要获得逐行历史记录,只需将要查看其差异的提交的SHA-1字符串添加到 URL 后的单词commit
,然后使用您感兴趣的文件名锚定它。对于相同的上面的文件:
https://github.com/mxcl/homebrew/commit/288f001e924d5365b79c279e4478f372a04011ae#SUPPORTERS.md
https://github.com/mxcl/homebrew/commit/288f001e924d5365b79c279e4478f372a04011ae#SUPPORTERS.md
回答by Peter Krauss
As @BurhanKhalid say, but here explaining as a "GitHub fast guide", with URL syntax:
正如@BurhanKhalid 所说,但这里用 URL 语法解释为“GitHub 快速指南”:
- Browse your project at
https://github.com/<USER>/<PROJECT>
... - ... then you have a URL ending with the file path:
https://github.com/<USER>/<PROJECT>/blob/master/<PATH>
- Now you have all, is only to change "blob/master" to "commits/master":
https://github.com/<USER>/<PROJECT>/commits/master/<PATH>
- 在
https://github.com/<USER>/<PROJECT>
...浏览您的项目 - ...然后你有一个以文件路径结尾的 URL:
https://github.com/<USER>/<PROJECT>/blob/master/<PATH>
- 现在你拥有了一切,只是将“blob/master”更改为“commits/master”:
https://github.com/<USER>/<PROJECT>/commits/master/<PATH>
PS: to remember "commits/master" click at the project's home in the "Commit" link.
PS:要记住“commits/master”,点击项目主页中的“Commit”链接。
Ops: there are a similar answer here, @TimHenigan expressed with http://github.com/<username>/<project>/commits/<branch>/<path/to/file>
Ops:这里有类似的答案,@TimHenigan 表示http://github.com/<username>/<project>/commits/<branch>/<path/to/file>
Question to GitHub developers team
GitHub 开发团队的问题
Why do you not offer a direct link for this kind of browsing? We need it, like Wikipedia readers need "history" link!
为什么不提供这种浏览的直接链接?我们需要它,就像维基百科的读者需要“历史”链接一样!
Ops, GitHub's team is listening to us?
Ops,GitHub 的团队在听我们说话吗?
Now (June 2014) when you browse through the folders, an icon appears, see "browse commits" above right. When you click, the tree/master
URL turns commits/master
.
现在(2014 年 6 月),当您浏览文件夹时,会出现一个图标,请参阅右上方的“浏览提交”。单击时,tree/master
URL 变为commits/master
。
Still missing to have the same for files, as showed here, but was an evolution.
仍然缺少对 files 具有相同的功能,如此处所示,但这是一种演变。
回答by Ynjxsjmh
I think git-historyis an alternative and good method for quickly browsing the history of files in any Git repository.
我认为git-history是快速浏览任何 Git 存储库中文件历史记录的另一种好方法。
You don't need to download anything. You only need to replace some text in the URL.
你不需要下载任何东西。您只需要替换 URL 中的一些文本。
Steps to do:
操作步骤:
- Go to a file in GitHub(or GitLab, or Bitbucket)
- Replace
github.com
withgithub.githistory.xyz
- 转到GitHub(或GitLab或Bitbucket)中的文件
- 替换
github.com
为github.githistory.xyz
There is Chromeand Firefoxextensions to add an Open in Git History
button on GitHub, GitLab and Bitbucket so that you don't need to memorize step 2.
有Chrome和Firefox扩展可以Open in Git History
在 GitHub、GitLab 和 Bitbucket 上添加按钮,这样你就不需要记住第 2 步。
For more information, you can go to its GitHub page.
有关更多信息,您可以转到其GitHub 页面。
回答by Aziz Alto
Check out https://github.com/pomber/git-historya very handy UI tool (and plugin) visualization of file changes through time.
查看https://github.com/pomber/git-history一个非常方便的 UI 工具(和插件)可视化文件随时间的变化。
回答by Rick
As of , if you want to view all the change records in a easy wayon GitHub, NO, I did not find an easy way to do that in browser.
截至目前,如果您想在 GitHub 上以简单的方式查看所有更改记录,不,我没有在浏览器中找到一种简单的方法。
How you view one commit change history on GitHub:
您如何在 GitHub 上查看一个提交更改历史记录:
- You visit any file, let's say
hello.cpp
on GitHub, click the "history" button, then you can see the commits that change this file. - Then by clicking each commit's "sha" button, you see the whole commit.
- Then you find
hello.cpp
, click "view file" button. And finally you only see the difference of this commit-
last commit.
- 你访问任何文件,比如说
hello.cpp
在 GitHub 上,点击“历史”按钮,然后你就可以看到改变这个文件的提交。 - 然后通过单击每个提交的“sha”按钮,您会看到整个提交。
- 然后你找到
hello.cpp
,点击“查看文件”按钮。最后你只能看到这次提交与-
上次提交的区别。
So if you want to look through all the history changes, you have to repeat the process above for so many times.. and open so many tabs...
因此,如果您想查看所有历史更改,则必须多次重复上述过程……并打开这么多选项卡……
You can use gitk [filename]
(GUI) or git log -p filename
(Command line) to view all history changes of a single file easily.
您可以使用gitk [filename]
(GUI)或git log -p filename
(命令行)轻松查看单个文件的所有历史更改。
Source: View the change history of a file using Git versioning
回答by xgqfrms
You can read this official article firstly, and then I will show you a demo!
你可以先阅读这篇官方文章,然后我给你演示一个demo!
https://developer.github.com/v3/repos/commits/
https://developer.github.com/v3/repos/commits/
Here is the demo, using the fetch API:
这是使用fetch API的演示:
PS: client_id
& client_secret
you should using yourself!
PS:client_id
&client_secret
你应该自己用!
let username = `xgqfrms-GitHub`;
repo = `Node-CLI-Tools`;
fetch(`https://api.github.com/repos/${username}/${repo}/commits`,{
data: {
client_id: '08ecc2f68d922f188xxx',
client_secret: '5846d428b5340812b76c9637eceaee979340bxxx'
}
})
.then((response) => response.json())
.then((json)=> {
console.log(`json = ${json}`);
return repos = json;
})
.then((repos)=>{
console.log(`repos = ${repos}`);
console.log(`repos = ${repos.length}`);
for (let i = 0; i < repos.length; i++) {
console.log(`repos${i} = ${repos[i].commit.message}`);
}
});
回答by gtria
Checkout out Little Differin the Google Chrome webstore. It's a Chrome extension that shows a sidebar displaying the commit history of a repository or a file.
在 Google Chrome 网上商店中查看Little Differ。这是一个 Chrome 扩展程序,它显示一个侧边栏,显示存储库或文件的提交历史记录。