git 如何查看分叉的 github 项目的差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3792989/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:36:24  来源:igfitidea点击:

How to view diff of a forked github project

gitdiffgithubforkmaster

提问by GDR

I have forked a project on github and need to have a set of changes I made since I forked, in diff format.

我已经在 github 上分叉了一个项目,并且需要在我分叉后以 diff 格式进行一组更改。

If you wonder - I've forked Apache httpd and I'm changing some code in core. Currently I'm not commiting any changes, running git diff, and use its output as a patch against vanilla httpd sources in an RPM building process. It is, of course, wrong, but I don't know how to do it properly. All I know is I need a diff in the end.

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

采纳答案by VonC

  • Add the original GitHub repo (the one you have forked) as a remote one on your local repo.
    (git remote add mainRepo github_url)
  • git fetch mainRepoto get the latest changes from that original "mainRepo".
  • git log HEAD..mainRepo/masterwill show you all your changes between the latest on mainRepo master branch and your current branch.
    git diff HEAD..mainRepo/masterwould display it in diff format.
  • 将原始 GitHub 存储库(您已分叉的那个)添加为本地存储库中的远程存储库。
    ( git remote add mainRepo github_url)
  • git fetch mainRepo从原始“mainRepo”获取最新更改。
  • git log HEAD..mainRepo/master将向您显示 mainRepo 主分支和当前分支上的最新版本之间的所有更改。
    git diff HEAD..mainRepo/master将以差异格式显示它。

In learn.GitHub:

learn.GitHub 中

git diff mainRepo/master...HEAD

would list all your changes since you have forked from mainRepo:

将列出自您分叉以来的所有更改mainRepo

This will not compare the last ‘master' branch snapshot and the last ‘dev' snapshot - it will instead compare the common ancestor of both with ‘dev'. That will tell you what changed since the branch point.

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

回答by beat

This is an old question, but I just found a very nice method to get a patch or diff file directly from Github.

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

When you are on your fork, there is a "Compare" link. Using that you are getting to the compare view.

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

Example

例子

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

Now you can manually add either ".diff" or ".patch" to the end of this url, and you get the file directly in your browser.

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

Example

例子

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

Source: https://github.com/blog/967-github-secrets

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

回答by rogerdpack

If you push a branch that tracks the "upstream" repo to your repository, then you can see the diff in github itself, too:

如果您将跟踪“上游”存储库的分支推送到您的存储库,那么您也可以在 github 本身中看到差异:

 git remote add mainRepo github_url
 git fetch mainRepo
 git branch main_repo_master mainRepo/master
 git push origin main_repo_master

Then see it online like this:

然后在网上看到是这样的:

https://github.com/rdp/mplayer-svn/compare/master…main_repo_master

https://github.com/rdp/mplayer-svn/compare/master...main_repo_master

ref: http://betterlogic.com/roger/2012/04/github-compare-commits

参考:http: //betterlogic.com/roger/2012/04/github-compare-commits

回答by AuthorProxy

Get parent/fork point sha1: git merge-base master HEADGet diff: git diff <sha1>

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

Or in one command: git difftool $(git merge-base master HEAD)

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

Which is the same as sugar command: git diff master...HEAD

与 Sugar 命令相同: git diff master...HEAD