我怎样才能生成github中两个分支之间的单个文件的差异 [英] How can I generate a diff for a single file between two branches in github

查看:433
本文介绍了我怎样才能生成github中两个分支之间的单个文件的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为单个文件生成差异文件,以显示两个版本之间的差异,这两个版本实际上是github中的标签。然后,我想通过电子邮件将此差异发送给某人,因此用于差异的github URL将是理想的。 github的比较视图将允许我为所有已更改的文件执行此操作,但这并不好,因为我的repo中有成千上万的文件。



我可以在命令行如下,但这并没有帮助,因为我需要通过电子邮件发送差异给别人:

  git diff tag1 tag2  -  path / to / file 

我在这里讨论了命令行版本:
将指向版本v0.9.0和v0.9.5之间发生的 LazyFixtures.cs 更改。



更新



在您的评论中指出您的差异太大而无法通过Web界面呈现,恢复到旧的命令行工具?您可以将diff的输出重定向到一个文件,然后将该文件作为电子邮件附件发送。

  $ git diff v0。 9.0 v0.9.5  -  LibGit2Sharp.Tests / LazyFixture.cs> /tmp/lazyfixture.diff 


I need to generate a diff for a single file that will show the differences between two versions, which are actually tags in github. I then want to send this diff to someone via email so a github URL for the diff would be ideal. The github compare view will allow me to do this for all changed files, but that's no good as there are thousands of files in my repo.

I can do this in the command line as follows, but this doesn't help as I need to send the diff to someone via email:

git diff tag1 tag2 -- path/to/file

I found the command line version discussed here: how can I see the differences in a designated file between a local branch and a remote branch?

解决方案

GitHub only exposes the way to show diff between two commits.

Provided those tags actually point to commits, the Url format would be something like

https://github.com/{user}/{repository}/compare/{from-tag}...{until-tag}

As an example, https://github.com/libgit2/libgit2sharp/compare/v0.9.0...v0.9.5 shows the diff between two versions of the LibGit2Sharp project. This diff includes all the modified files.

If you want to retrieve an url that targets a specific file:

  • Switch to the Files Changed tab

  • Click on the Show Diff Stats button (This will display the list of modified files as links)

  • Copy to the clipboard the link of the specific file you're after... and Tada! You're done.

For instance, given the diff above, the link https://github.com/libgit2/libgit2sharp/compare/v0.9.0...v0.9.5#diff-11 will point to the LazyFixtures.cs changes that occured between version v0.9.0 and v0.9.5.

Update

Following your comment which states that your diff is too big to be rendered through the Web interface, how about reverting to good old command line tooling? You could redirect the output of the diff to a file and then send the file as an email attachment.

$ git diff v0.9.0 v0.9.5 -- LibGit2Sharp.Tests/LazyFixture.cs > /tmp/lazyfixture.diff

这篇关于我怎样才能生成github中两个分支之间的单个文件的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆