1
我需要在重构(在那里我改变了日志库)之后做一个逆git diff
,找到与我需要单独提交的主重构无关的几行。我读过这question和-G
标志看起来很有前途,但如何反转呢?即不包含字符串log
的更改。如何在不使用特定关键字的情况下对git diff进行grep忽略更改?
我需要在重构(在那里我改变了日志库)之后做一个逆git diff
,找到与我需要单独提交的主重构无关的几行。我读过这question和-G
标志看起来很有前途,但如何反转呢?即不包含字符串log
的更改。如何在不使用特定关键字的情况下对git diff进行grep忽略更改?
使用您的pager进行此类任务。您的寻呼机是一个程序,它允许您一次完成诸如git diff
和git log
以及许多其他命令的输出。它具有强大的搜索功能,无论底层命令如何,这些功能都能正常工作。
这些日子通常的寻呼机是less
,在以前的默认more
播放。 man less
将让你了解它的所有功能,包括...
/pattern
Search forward in the file for the N-th line containing the pattern. N
defaults to 1. The pattern is a regular expression, as recognized by the
regular expression library supplied by your system. The search starts at
the first line displayed (but see the -a and -j options, which change this).
Certain characters are special if entered at the beginning of the pattern;
they modify the type of search rather than become part of the pattern:
^N or !
Search for lines which do NOT match the pattern.
所以/
然后!
,你会看到Non-match /
。然后输入log
或任何你想跳过。 less
仍然会突出显示log
的所有实例,但您可以前后移动所有与n
和N
不匹配的行。
更好的解决方案是git add
只是那些线分别使用git add -p
。这将允许您逐个分段更改个人区块,跳过更改或整个文件。然后提交这些作品。见Interactive Staging in the Git Book。
'-G'接受一个正则表达式,所以写一个“不包含'log'”的正则表达式。 –
我不认为有一个简单的方法来实现这一点,最接近的可能是:git diff --unified = 0(以摆脱大部分混乱),然后将结果输入到逆匹配中,如下所示: grep -v“log” – ericat