chiborg
chiborg

Reputation: 28134

How to get diff output without preceding characters?

Is there a way to present a diff that is more copy-paste friendly, meaning no preceding characters like in the unified format (+-) or default format (<>)? Perhaps surrounding the changed code with markers on extra lines like this:

some_context code
++++ Added 3 lines:
line 1
line 2
line 3
++++ END added lines
some context code
---- Deleted 1 line:
deleted line
---- END deleted line
some context code

instead of

some_context code
+ line 1
+ line 2
+ line 3
some context code
- deleted line
some context code

Upvotes: 0

Views: 121

Answers (1)

chiborg
chiborg

Reputation: 28134

After reading the documentation, it turns out you can indeed specify your own format with the line-format and group-format parameters.

Here is an example from the documentation that does what i need:

diff \
        --unchanged-group-format='' \
        --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
     %<' \
        --new-group-format='-------- %dN line%(N=1?:s) added after %de:
     %>' \
        --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
     %<-------- to:
     %>' \
        old new

Links:

Upvotes: 1

Related Questions