Git:删除diff中的前后加/减行 [英] Git: remove leading plus/minus from lines in diff

查看:151
本文介绍了Git:删除diff中的前后加/减行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单,虽然我没有找到答案的运气。



我想从每行中删除前导加号/减号 git diff 。在你问我为什么要这样做的时候,请允许我概述我的理由:


  1. 恰好为80个字符的行会溢出一个字符,它看起来简单尴尬

  2. 着色足以区分添加/删除操作
  3. 我更愿意保留终端窗口宽度为80个字符(而不是任意的81个字符)以保持与我在终端中执行的所有其他操作保持一致( git 之外)

有没有这样的配置选项?如果没有,我怎么能这样做,仍然允许我通过比较小于 -style


解决方案

一个选项是使用 sed 从diff中移除不需要的字符,同时保留颜色:

  git diff --color | sed -rs / ^([^  -  +] *)[ -  +] / \\1 /| less -r 

(请注意,您还需要删除前导空格,因为它是由差异。)


My question is rather simple, though I have had no luck finding an answer.

I'd like to remove the leading plus/minus symbols from each line in git diff. Before you ask why I wish to do this, allow me to outline my reasons:

  1. Lines that are exactly 80 chars will overflow by a single character, which just looks plain awkward
  2. The coloring is enough for me to distinguish between additions/deletions
  3. I'd prefer to keep my Terminal's window width at 80 chars (as opposed to an arbitrary 81 chars) to maintain consistency with everything else I do in my Terminal (outside of git)

Is there some config option for doing this? If not, how can I do this in a way that still allows me to page through my diff less-style?

Any insight would be greatly appreciated.

解决方案

One option is to use sed to remove the undesired character from diff, while preserving the color:

git diff --color | sed -r "s/^([^-+ ]*)[-+ ]/\\1/" | less -r

(Note that you need to remove the leading space as well, as it is emitted by diff.)

这篇关于Git:删除diff中的前后加/减行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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