51

I've seen people show diffs of their code from other forks to illustrate a point in github like on this pull request thread: https://github.com/osTicket/osTicket/pull/3035

I think it would be really helpful to show the diff of the commit from the current branch. How do you do it?

3 Answers 3

85

You can pull the branch to your local copy, and make your modification. After that, copy the output of git diff and paste to GitHub as follows.

```diff
your diff file contents
```
3
  • Thank you. This is close but doesn't seem to color-code it the way that the examples do.
    – catbadger
    Commented Apr 14, 2016 at 22:42
  • 4
    @catbadger did you type the diff specifier? I tried your diff in the comments and it works well.
    – xuhdev
    Commented Apr 14, 2016 at 23:00
  • 2
    Is it possible to display a side-by-side diff?
    – Luciano
    Commented Jun 2, 2021 at 9:31
45

It's worth mentioning how to write the diff:

```diff
- line removed
+ line added
```
0

Note though this will not work well with diff output generated with git's --word-diff options, since the - and + are not at the beginning of the line:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.