Search code examples
gitgit-diff

How do I view a git diff in a text editor?


How do I view a git diff in a plain old text editor like Atom? I don't want to set up or use a diff tool, I just want to view the diff in any basic text editor.

Answers to other questions I've seen talk about setting up a diff tool, but I just want to specify some random text editor.


Side question:

  • What's the difference between a diff tool and any text editor?

Solution

  • How do I view a git diff in a plain old text editor like Atom? I don't want to set up or use a diff tool, I just want to view the diff in any basic text editor.

    Diff output is just text, so you can redirect it to a file and open that file, or (depending on the editor and platform) pipe the input directly to the editor.

    If you did want run your editor as the diff tool, the documentation describes how the editor is invoked. You may want a wrapper script to invoke atom with the environment variables in the correct place on the command line.

    Side question: What's the difference between a diff tool and any text editor?

    A generic text editor is unlikely to display diffs as nicely as a dedicated tool. At least, if it recognizes the format, it may highlight the diff-specific parts.

    A real difftool will generally give you the opportunity to see both the old and new versions of the file, as well as showing visually where the changes sit. It may highlight intra-line changes too (the diff itself is line-based).


    I'm generally against pictures of text, but since we're really discussing the interface ...

    1. output from git diff opened in text editor: diff opened in text editor This is hardly different than just reading the diff in the terminal, so I don't see much benefit. It does highlight the index line, but that's only really useful if I'm scanning through multiple hunks in a single diff.

    2. GVim fugitive plugin showing the same change: change in gvim with fugitive This is the view from inside my editor with the fugitive plugin. You can see the intra-line highlight where I removed a space from the join line. It'll even update live if I keep typing in the right pane. This is also the only one that correctly syntax highlights the source code.

    3. same change opened in meld with git difftool same change in meld from difftool This is the friendliest view of how a change fits into the whole file IMO.