38

我已经在 github 上创建了一个项目,并且需要对我进行的一组更改进行更改,这些更改是 diff 格式的。

如果您想知道 - 我已经分叉了 Apache httpd,并且我正在更改一些核心代码。目前我没有提交任何更改,运行 git diff,并在 RPM 构建过程中将其输出用作针对 vanilla httpd 源的补丁。当然,这是错误的,但我不知道如何正确地做到这一点。我所知道的是我最终需要一个差异。

4

4 回答 4

35

在线解决方案:

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年的原始答案:

  • 将原始 GitHub 存储库(您已分叉的那个)添加为本地存储库中的远程存储库。
    ( git remote add mainRepo github_url)
  • git fetch mainRepo从原始“mainRepo”中获取最新更改。
  • git log HEAD..mainRepo/master将显示您在 mainRepo 主分支的最新版本和您当前的分支之间的所有更改。
    git diff HEAD..mainRepo/master将以差异格式显示它。

learn.GitHub 中

git diff mainRepo/master...HEAD

将列出您从以下位置分叉后的所有更改mainRepo

这不会比较最后一个“master”分支快照和最后一个“dev”快照——而是将两者的共同祖先与“dev”进行比较。这将告诉您自分支点以来发生了什么变化。

于 2010-09-25T08:51:14.613 回答
11

这是一个老问题,但我刚刚找到了一个非常好的方法来直接从 Github 获取补丁或差异文件

当你在你的叉子上时,有一个“比较”链接。使用它,您将进入比较视图。

例子

https://github.com/luisgoncalves/xades4j/compare/master...beat2:master

现在您可以手动将“.diff”或“.patch”添加到此 url 的末尾,并直接在浏览器中获取文件。

例子

https://github.com/luisgoncalves/xades4j/compare/master...beat2:master.diff

来源:https ://github.com/blog/967-github-secrets

于 2017-05-10T12:17:50.680 回答
6

如果您将跟踪“上游”存储库的分支推送到您的存储库,那么您也可以在 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

于 2012-12-19T04:58:56.197 回答
2

获取父/叉点 sha1:git merge-base master HEAD 获取差异:git diff <sha1>

或者在一个命令中:git difftool $(git merge-base master HEAD)

这与糖命令相同:git diff master...HEAD

于 2015-10-16T20:11:47.157 回答