git diff必须仅从某个特定的偏移量或字符列中进行比较。

huangapple go评论50阅读模式
英文:

git diff must compare only from a certain offset or char. column in a line

问题

以下是翻译后的内容:

如何在git diff中仅从某一行中的特定偏移列进行比较,例如下面的两个日志应该没有区别

index 7e2d6d7..cb88ce6
--- a/var/log/lightdm/lightdm.log
+++ b/mnt/OSraw/var/log/lightdm/lightdm.log
@@ -1,46 +1,175 @@

-[+0.00s] DEBUG: Logging to /var/log/lightdm/lightdm.log
-[+0.00s] DEBUG: Starting Light Display Manager 1.32.0, UID=0
-[+0.00s] DEBUG: Loading configuration dirs from /usr/share/lightdm/lightdm.conf.d
-[+0.00s] DEBUG: Loading configuration dirs from /usr/local/share/lightdm/lightdm.conf.d
-[+0.00s] DEBUG: Loading configuration dirs from /etc/xdg/lightdm/lightdm.conf.d
-[+0.00s] DEBUG: Loading configuration from /etc/lightdm/lightdm.conf
-[+0.00s] DEBUG: Registered seat module local

+[+0.01s] DEBUG: Logging to /var/log/lightdm/lightdm.log
+[+0.01s] DEBUG: Starting Light Display Manager 1.32.0, UID=0
+[+0.01s] DEBUG: Loading configuration dirs from /usr/share/lightdm/lightdm.conf.d
+[+0.01s] DEBUG: Loading configuration dirs from /usr/local/share/lightdm/lightdm.conf.d
+[+0.01s] DEBUG: Loading configuration dirs from /etc/xdg/lightdm/lightdm.conf.d
+[+0.01s] DEBUG: Loading configuration from /etc/lightdm/lightdm.conf
+[+0.01s] DEBUG: Registered seat module local

请帮忙!

英文:

How git diff compare only from a certain offset column in a line, eg the two log below should be not different

index 7e2d6d7..cb88ce6
--- a/var/log/lightdm/lightdm.log
+++ b/mnt/OSraw/var/log/lightdm/lightdm.log
@@ -1,46 +1,175 @@

-[+0.00s] DEBUG: Logging to /var/log/lightdm/lightdm.log
-[+0.00s] DEBUG: Starting Light Display Manager 1.32.0, UID=0
-[+0.00s] DEBUG: Loading configuration dirs from /usr/share/lightdm/lightdm.conf.d
-[+0.00s] DEBUG: Loading configuration dirs from /usr/local/share/lightdm/lightdm.conf.d
-[+0.00s] DEBUG: Loading configuration dirs from /etc/xdg/lightdm/lightdm.conf.d
-[+0.00s] DEBUG: Loading configuration from /etc/lightdm/lightdm.conf
-[+0.00s] DEBUG: Registered seat module local

+[+0.01s] DEBUG: Logging to /var/log/lightdm/lightdm.log
+[+0.01s] DEBUG: Starting Light Display Manager 1.32.0, UID=0
+[+0.01s] DEBUG: Loading configuration dirs from /usr/share/lightdm/lightdm.conf.d
+[+0.01s] DEBUG: Loading configuration dirs from /usr/local/share/lightdm/lightdm.conf.d
+[+0.01s] DEBUG: Loading configuration dirs from /etc/xdg/lightdm/lightdm.conf.d
+[+0.01s] DEBUG: Loading configuration from /etc/lightdm/lightdm.conf
+[+0.01s] DEBUG: Registered seat module local

Please help out!

答案1

得分: 2

你正在寻找textconv的差异。虽然文档中说它用于查找二进制文件的差异,但这里所谓的“二进制”实际上指的是在其原始形式下难以处理的任何内容。

echo lightdm.log diff=myfilter >> .git/info/attributes

上述的sed命令会在差异查看它们之前从行中去除前面的括号括起的单词,只是在初始列上涂白了一定数量的列,你可以像这样做:s,..........,----------,

英文:

You're looking for textconv diffs. While the docs say it's for diffing binaries, what "binary" means here is really just anything that's difficult to work with in its original form.

git config diff.myfilter.textconv "sed 's,^\\[[^]]*] , ,'" 
echo lightdm.log diff=myfilter >> .git/info/attributes

that sed strips leading bracketed words off the lines before the diff sees them, to just white out a fixed number of initial columns you'd do something like s,..........,----------,.

huangapple
  • 本文由 发表于 2023年5月7日 16:36:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192903.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定