Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

git - How to view diff of a forked github project

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Online solution:

get /repos/{owner}/{repo}/compare/{base}...{head}

The "compare two commits" API does support multiple repositories:

Both :base and :head must be branch names in :repo.
To compare branches across other repositories in the same network as :repo, use the format <USERNAME>:branch.

Example:

https://api.github.com/repos/octocat/hello-world/compare/master...abejpn:master

Or with a GitHub URL:

https://github.com/octocat/Hello-World/compare/master...abejpn:master


Original answer 2010:

  • 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 mainRepo to get the latest changes from that original "mainRepo".
  • git log HEAD..mainRepo/master will show you all your changes between the latest on mainRepo master branch and your current branch.
    git diff HEAD..mainRepo/master would display it in diff format.

In learn.GitHub:

git diff mainRepo/master...HEAD

would list all your changes since you have forked from 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...