我已经在 github 上创建了一个项目,并且需要对我进行的一组更改进行更改,这些更改是 diff 格式的。
如果您想知道 - 我已经分叉了 Apache httpd,并且我正在更改一些核心代码。目前我没有提交任何更改,运行 git diff,并在 RPM 构建过程中将其输出用作针对 vanilla httpd 源的补丁。当然,这是错误的,但我不知道如何正确地做到这一点。我所知道的是我最终需要一个差异。
在线解决方案:
get /repos/{owner}/{repo}/compare/{base}...{head}
“比较两个提交” API确实支持多个存储库:
两者
:base
和都:head
必须是:repo
.
要比较同一网络中其他存储库的分支:repo
,请使用<USERNAME>:branch
.
例子:
https://api.github.com/repos/octocat/hello-world/compare/master...abejpn:master
或者使用 GitHub URL:
https://github.com/octocat/Hello-World/compare/master...abejpn:master
2010年的原始答案:
git remote add mainRepo github_url
)git fetch mainRepo
从原始“mainRepo”中获取最新更改。git log HEAD..mainRepo/master
将显示您在 mainRepo 主分支的最新版本和您当前的分支之间的所有更改。git diff HEAD..mainRepo/master
将以差异格式显示它。git diff mainRepo/master...HEAD
将列出您从以下位置分叉后的所有更改mainRepo
:
这不会比较最后一个“master”分支快照和最后一个“dev”快照——而是将两者的共同祖先与“dev”进行比较。这将告诉您自分支点以来发生了什么变化。
这是一个老问题,但我刚刚找到了一个非常好的方法来直接从 Github 获取补丁或差异文件。
当你在你的叉子上时,有一个“比较”链接。使用它,您将进入比较视图。
例子
https://github.com/luisgoncalves/xades4j/compare/master...beat2:master
现在您可以手动将“.diff”或“.patch”添加到此 url 的末尾,并直接在浏览器中获取文件。
例子
https://github.com/luisgoncalves/xades4j/compare/master...beat2:master.diff
如果您将跟踪“上游”存储库的分支推送到您的存储库,那么您也可以在 github 本身中看到差异:
git remote add mainRepo github_url
git fetch mainRepo
git branch main_repo_master mainRepo/master
git push origin main_repo_master
然后在网上看到是这样的:
https://github.com/rdp/mplayer-svn/compare/master …main_repo_master
参考:http ://betterlogic.com/roger/2012/04/github-compare-commits
获取父/叉点 sha1:git merge-base master HEAD
获取差异:git diff <sha1>
或者在一个命令中:git difftool $(git merge-base master HEAD)
这与糖命令相同:git diff master...HEAD