3

讓 git blame 可以忽略掉某些 restyle/reformat 的 commit

 8 months ago
source link: https://blog.gslin.org/archives/2023/12/23/11545/%e8%ae%93-git-blame-%e5%8f%af%e4%bb%a5%e5%bf%bd%e7%95%a5%e6%8e%89%e6%9f%90%e4%ba%9b-restyle-reformat-%e7%9a%84-commit/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

讓 git blame 可以忽略掉某些 restyle/reformat 的 commit

在 X (Twitter) 上看到這則推,提到了可以讓 git blame 自動忽略掉某些 restyle 或是 reformat 的 commit:

查了一下是在 2019 年八月出的 2.23.0 引入的,從 Documentation/RelNotes/2.23.0.txt 可以看到說明:

 * "git blame" learned to "ignore" commits in the history, whose
   effects (as well as their presence) get ignored.

除了可以在專案內單獨設定外,也可以在 ~/.gitconfig 內設定:

[blame]
    ignoreRevsFile = .git-blame-ignore-revs

我是拿 rss-bridge 裡的 bridges/ARDMediathekBridge.php 測試,可以看到這個檔案最後的修改是「Reformat codebase v4」這包,也就是被放進 ignore 清單的 commit。

這個 commit 中,對 ARDMediathekBridge.php 這個檔案的 diff 則可以在「這裡」看到。

從 diff log 可以看到幾乎是所有的縮排都被改變了,但 GitHub 上面的 Blame 資訊,以及拉下來後用 git blame 或是 tig blame 可以注意到大多數有意義的地方都有被找出來「還原」,只有很簡單的內容沒有被辨識出來 (像是整行只有 /* 或是 { 之類的地方)。

看起來還是蠻有用的,先丟進 dotfiles 裡面了...

Related

Python 的 Black

在 Hacker News 上看到 Black 這個幫你處理 Python 程式碼的工具:「Black, the uncompromising Python code formatter, is stable (pypi.org)」。 Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You…

January 31, 2022

In "Computer"

在 .gitignore 裡面忽略掉 .gitignore...

在 Hacker News 上看到「Git ignores .gitignore with .gitignore in .gitignore」這個搞事的功能,可以在 .gitignore 內把 .gitignore 忽略掉 XDDD 這真虧作者想的到這樣的玩法 XDDD 在 Hacker News 上也有看到一些有趣的東西,像是 globally ignore list 之類的:「Git ignores .gitignore with .gitignore in .gitignore (rubenerd.com)」。

May 19, 2022

In "Computer"

被動靈氣加成:用 git rerere 解決同樣的 conflict 問題

Git 上一個很好用的設定,不需要改變原來的工作模式,有種「被動靈氣」的感覺 XD 在 Twitter 上看到這則推: 整理了三個 GIT 比較少用的指令:bisect 是利用二元對切,自動協助 checkout commit 快速找到第一個發生問題的 commit。 rerere 是讓解衝突的方式,可以重複利用。worktree 則是在同一個 repo 下直接新建不同的工作目錄,方便工作上直接對照或查看。#GIThttps://t.co/YsObFucOyU— mouson (@mouson) March 24, 2019 裡面提到了 git rerere 這個指令,投影片裡面雖然有給方法,不過一時間沒看懂... (oops) 找了一下官方文件與其他文件後發現其實意外的簡單,就是在 .gitconfig 設定檔內開啟個 flag 後就沒事了,其他的動作照以前的方式走。Git 的被動技能就是在每次遇到 conflict 以及解決的時候就會記錄下來,當下次遇到同樣的情況就自動幫你解。 先開起來再說,之後來看看有什麼副作用再來抱怨 XDDD

March 26, 2019

In "Computer"

a611ee8db44c8d03a20edf0bf5a71d80?s=49&d=identicon&r=gAuthor Gea-Suan LinPosted on December 23, 2023Categories Computer, Murmuring, Programming, SoftwareTags blame, code, format, git, ignore, reformat, restyle, source, style

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)

Post navigation


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK