17

Somebody is sending me patches generated by "git format-patch".

Is there a gui (on linux) that can open these .patch files?

I've tried many diff gui but all they do is compare two existing files/folders. None can display the patch, except kompare which spits a "The diff is malformed. Some lines could not be parsed and will not be displayed in the diff view." everytime.

big_gie
  • 2,829
  • 3
  • 31
  • 45

6 Answers6

53

I've made a tool to view diff side-by-side: https://app.box.com/s/l8rmp281aptq711fqwve

Screenshot: enter image description here

Now it was updated to v0.4 to support file list.

Source code: https://github.com/megatops/PatchViewer

megatops
  • 533
  • 4
  • 4
  • 3
    Why was this answer downvoted? I find it a useful tool! – Bert Regelink Dec 13 '14 at 19:52
  • 1
    Nice tool! Downloadable as a single .html file, which according to [NoScript](https://noscript.net/) doesn't attempt to load any external scripts. Thanks! – akavel Feb 04 '15 at 15:15
  • I see you have created 2 accounts. Please see http://stackoverflow.com/help/merging-accounts if you wish to merge them (https://stackoverflow.com/users/4238572/ding-zhaojie, https://stackoverflow.com/users/4238814/ding-zhaojie) – Matt Dec 11 '15 at 23:35
  • 3
    This should be the top answer for this question. #1 it works #2 simple install (download 1 file) #3 minimal deps (no external that I can tell) #4 is fast #5 looks good too! – ChuckB Oct 12 '18 at 02:22
  • Outstanding tool. Simply download the [html file above](https://raw.githubusercontent.com/megatops/PatchViewer/master/PatchViewer.html), open it in your browser, this allows you to open the patch files and it shows the diff files before and after side by side, like the picture shows. Superb, should be built into git. – boardtc Sep 27 '21 at 14:55
  • Just for fun, [I hacked into a fiddle quickly](https://jsfiddle.net/vx968eyg/). I'm not sure if the app.box.com url used to run it, but it looks like it's just dumping the script now. – ruffin Oct 03 '22 at 15:20
11

I found a solution:

cat patch | colordiff | less -RS

Further reading: http://www.markusbe.com/2009/12/how-to-read-a-patch-or-diff-and-understand-its-structure-to-apply-it-manually/ (archived copy)

ruffin
  • 16,507
  • 9
  • 88
  • 138
Endle_Zhenbo
  • 538
  • 4
  • 23
5

They're pretty easy to read, but if you want to see the entire context of the file, the best way is to apply them with git-am:

git am foo.patch
git difftool ORIG_HEAD

If you like it, it's already committed. If not:

git reset --hard ORIG_HEAD
Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94
  • 1
    I guess that's the reason why no guy is doing what I'm asking. Since git is so powerful, doing everything in git directly is possible. – big_gie Aug 04 '11 at 22:23
  • 1
    I think I'll do this: 1) create a branch, 2) apply all patches, 3) review with any gui, 4) merge the branch or cherry-pick some commits. – big_gie Aug 04 '11 at 22:25
  • I'd like to add that to review difference between commits, "git-meld" from https://github.com/wmanley/git-meld is amazing. So: 1) Branch 2) apply patches 3) git meld commit1..commit2 – big_gie Aug 05 '11 at 15:33
  • as a 2 cents, personally I would do as above but use git diff all http://stackoverflow.com/questions/1220309/git-difftool-open-all-diff-files-immediately-not-in-serial – chrispepper1989 Apr 30 '14 at 15:06
3

The .diff and .patch files that git generates are just plain-text diff files.

Most text editors on linux should be able to open and syntax-highlight the diff files. Emacs and vim should be able to view them without any problem, as should gedit, kate, or pretty much any other syntax-highlighting text editor.

If you don't need syntax highlighting, less, cat, or anything else that displays plain text should also show you the changes.

Justin Weiss
  • 1,128
  • 7
  • 10
-1

Git Cola includes an "Apply Patches" dialog that can be launched from the Actions menu, or via the git cola am sub-command. You can open patches in this dialog and display the contents with diff syntax highlighting.

This feature is available in master by cloning the repo and will be in the upcoming v3.3 release.

davvid
  • 339
  • 3
  • 4
-3

They are supposed to be human-readable text. Open them in a text editor.

Edit: or apply the patch on a branch, then you can use whatever tool you normally use to compare branches.

Edit 2: oh you already thought of that, never mind.

LaC
  • 12,624
  • 5
  • 39
  • 38
  • 3
    Of course, but a gui is always nice to have. For example, a smart one could show you that on one extra long line which character changed. Meld will show you the two lines side by side and highlight the changed character. Looking at the patch in a text editor won't reveal easily this small change. – big_gie Aug 04 '11 at 22:20