Advent of Patterns: Diffs | James’ Coffee Blog


This article is the seventeenth edition of the Advent of Patterns series. In this series, running from December 1st to December 24th 2024, I will document one design or programming pattern I have noticed recently. Read more about this series.

A “diff” shows the difference between two states of a document. You can use a diff to understand what has been added, changed, removed, and moved within a document

Diffs are often accompanied by metadata such as who made each change in a document, when the change was made, and an identifier that refers to a checkpoint of the document when a change was made (i.e. a wiki history, a Git commit).

Diffs are commonly used in Git, software used to manage versions of code. GitHub, a place where you can store code using the Git protocol, provides visual diffs that show how files have changed between “commits.” Commits are checkpoints of a file that have been explicitly saved into the history of a project by a developer.

The GitHub interface provides a diff visualisation which can be used to evaluate changes in a file. Here is what a diff looks like on GitHub:

A diff between two commits in GitHub. The most recent commit contains two additions, denoted by green lines

The red line indicates that a line was removed or changed. A green line indicates that an addition was made. In the diff, there are two columns of line numbers: the first column corresponds with the file in its previous state, and the second column corresponds with the new state of the file.

The diff shows a few unchanged lines before and after each change. This information allows you to understand the context of the change. This is useful to help readers better understand how the change impacts the file. The diff also lists all changed files, so you can navigate between the files that have changed.

You can open this interface both when comparing different commits in the history of a file, or when reviewing changes on a branch. When you review changes, seeing a diff can help you better understand exactly what has changed and where changes have been made.

MediaWiki, a wiki tool, also supports diffs. You can compare the state of a wiki page to its previous version, or to the current version.

Here is what a diff looks like on the IndieWeb wiki, which uses MediaWiki:

A diff between two changes in MediaWiki. The most recent commit contains several additions marked by a plus icon.

In the diff, we can see what lines have been added and removed. Line numbers are used to indicate the exact location of changes. Lines before and after a change are displayed to show a user the context surrounding a change.

In this interface, the versions are displayed side by side. This allows a user to compare the previous and current version of the file.

With diffs, users can compare previous and current versions of a file. Diffs are commonly used as a tool in reviewing and evaluating changes.

The diff pattern is related to version history that I discussed earlier in this series. With that said, version histories do not necessarily need to provide diffs. A version history can link to a full snapshot of a piece of data at a point in time instead of a comparison. In practice, however, version histories commonly display diffs so that users are better able to see how data has changed over time.

In what places have you seen diffs?



Source link

Visited 1 times, 1 visit(s) today

Related Article

潘宏彬逝世終年63歲 曾與劉德華傳「斷背」到絕交 | am730

出版:2026-Apr-17 13:11 更新:2026-Apr-17 13:11 潘宏彬逝世終年63歲 。 曾參演TVB劇集《新紮師兄》飾演陳厚德的潘宏彬,今日(17日)傳出離世消息,享年63歲。其死訊由最新一屆「香港電影金像獎」特刊內的悼念名單公開,當中列明潘宏彬於今年與世長辭,消息一出令不少觀眾感到惋惜。 經典劇集 潘宏彬出身TVB第10期藝員訓練班,同期同學還有劉德華、梁家輝、戚美珍及徐錦江等,潘宏彬拍過多部經典劇集,包括《獵鷹》、《鹿鼎記》、《神鵰俠侶》、《畫出彩虹》等,1988年他轉戰台灣市場拍過幾部台劇,直至1998 年,潘宏彬退出娛樂圈,轉行任職地產經紀,2014年,他再次回歸影壇,為《微交少女》客串演出,成為他人生最後的一部作品。 潘宏彬與劉德華非常老友。 劉德華老友 外形俊朗的潘宏彬與劉德華識於微時,交情一度非常深厚。劉德華對這位老友相當關照,不僅邀請他擔任演唱會嘉賓及電影配角,更曾以高薪十萬元一個月安排他在歌迷會任職。早年二人關係密切,甚至惹來外界對他們有不實的「斷背」揣測,當時劉德華激動否認,潘宏彬亦澄清已有穩定交往的日籍女友。 斷絕來往 隨着潘宏彬退出演藝界,轉投地產行業,他與圈中人幾乎斷絕所有聯繫,連昔日好友劉德華亦坦言未能維繫這份友情,對此深感遺憾。潘宏彬則曾在受訪時豁達表示,真正的友誼毋須每日見面來衡量。不過,及後又有消息指,二人已經絕交,劉德華早年於台灣綜藝節目《康熙來了》訪問中,曾提及與一位訓練班同學絕交十多年的往事,理由是該朋友介入另一好友的感情糾紛,並發生越軌行為,當時他未有指名道姓,僅透露是圈內同期同學。 ADVERTISEMENT 送健之堂舒壓好眠足湯 x 石墨烯足浴袋 Source link

I shot over 200 photos with Galaxy S26 Ultra vs. Galaxy S26 — here’s the winner

If you’re thinking about upgrading your phone and considering Samsung’s new flagship lineup, you might be wondering which one to get: the Galaxy S26 or Galaxy S26 Ultra. From a price perspective, there’s a common assumption that the more expensive phone is going to deliver better camera performance — but you might be surprised. That’s

Sands Opens Milestone Fifth Edition With John Carney’s ‘Power Ballad’ 

The Sands International Film Festival opened Friday evening, marking a new milestone for the Scottish event: its fifth year in operations. “What nobody tells you at the start of new things is just how fragile beginnings can be,” Festival Director Ania Trzebiatowska said in her opening speech on Friday.  “Half of new ventures don’t make

Will Trent Season 4 Episode 16 Release Date, Time, Where to Watch

Will Trent Season 4 Episode 16’s release date and time is closer than you think. In the previous episode, titled “The Blank Expanse of Nothing,” Will agrees to meet Adelaide in the hope of saving his Uncle Antonio. Unknown to him, Amanda is secretly trying to find details about the Commander, who has a connection to Will’s

EUR/USD Weekly Outlook - ActionForex

EUR/USD Weekly Outlook – ActionForex

EUR/USD’s rise from 1.1408 extended higher to 1.1848 last week, but failed to take out 61.8% retracement of 1.2081 to 1.1408 at 1.1824 decisively. Initial bias is turned neutral this week first. On the upside, sustained trading above 1.1824 will pave the way to retest 1.2081 high. However, firm break of 1.1662 support will bring

Serie A: Napoli vs. Lazio – probable line-ups, where to watch on TV

Antonio Conte will look to Kevin De Bruyne, Scott McTominay and Rasmus Hojlund for Napoli’s home Serie A clash against Maurizio Sarri’s Lazio. It kicks off at 18:00 CET (17:00 BST) at the Stadio Maradona in Naples. Advertisement The home side is without the injured David Neres, Giovanni Di Lorenzo and Antonio Vergara, while Romelu

Pope Leo XIV and Trump clash over war, peace and the church

Eric J. Lyman, Special to USA TODAY April 18, 2026, 3:01 a.m. ET ROME − A priest celebrates a weekday mass for a couple of dozen faithful at the Basilica of St. Augustine, the main Augustinian church in the Italian capital. The congregation’s thin voices echo amid scaffolding for repairs and the shuffling of tourists

US President Donald Trump speaks during a Turning Point USA event at the Dream City Church on April 17, 2026 in Phoenix, Arizona. (File Photo/Getty Images via AFP)

Trump expands claim, says he stopped 10 wars including Iran and Lebanon

US President Donald Trump on Friday expanded on his previous claim of “stopping eight wars”, saying if he were to include the war in Iran and Lebanon, it would be “10 wars” that he has stopped. US President Donald Trump speaks during a Turning Point USA event at the Dream City Church on April 17,

Brentford vs. Fulham prediction, where to watch, Premier League standings

April 18, 2026, 2:30 a.m. ET The Premier League’s Saturday slate kicks off with Brentford hosting Fulham at Gtech Community Stadium in a West London derby. The Bees are in seventh place in the table and have drawn their last four league matches, most recently a 2-2 result against Everton last weekend. Keith Andrews’ side

Get ready for a potential stock market crash

Image source: Getty Images With geopolitical tensions on the rise, energy prices spiking from trade route disruptions in the Middle East, and food also at risk of becoming far more expensive, fears of a stock market crash are creeping back into investors’ minds. However, by taking the right steps, investors can not only protect their

Meta又一波大規模裁員!「這時」先砍8000人 下半年還有第2波 | 三立iNEWS | 三立新聞網 SETN.COM

2026/04/18 14:11 財經中心/彭淇昀報導 在AI浪潮推動下,社群平台Facebook母公司Meta Platforms傳出「大規模裁員」消息。有內部人士指出,Meta預計於5月20日展開首波裁員,規模約占全球員工數10%,約8000人,且公司內部評估,下半年恐還將進行第二波人力縮減。 Meta預計於5月20日展開首波裁員,規模約占全球員工數10%,約8000人,且公司內部評估,下半年恐還將進行第二波人力縮減。(圖/翻攝自PIXABAY) 根據《路透社》報導,儘管Meta近年營收與獲利維持高檔,2025年淨利達600億美元(約新台幣1.8兆元),但公司決策重心已轉向AI發展,執行長祖克柏(Mark Zuckerberg)正持續擴大相關投資,並以降低人力成本作為支撐策略之一,目標是打造更扁平化、效率更高的組織架構。 消息人士透露,這波裁員並非一次性措施。除5月的行動外,Meta內部仍在規劃後續調整,整體裁員比例不排除進一步擴大,實際幅度將取決於AI技術在優化流程與取代部分管理功能上的進展。 從產業面來看,類似趨勢正在科技業擴散。包括亞馬遜(Amazon)近幾個月裁撤3萬名員工、金融科技公司Block也在2月進行裁員,企業普遍將原因指向AI帶來的效率提升與成本結構重整。根據全球科技業裁員情況網站Layoffs.fyi報告指出,2026年至今科技業裁員人數已達約7.3萬人,2024年全球科技業共15.3萬人失業,顯示產業正加速轉型。 回顧過去,Meta曾在2022年底至2023年初進行大規模裁撤,當時影響約2.1萬名員工,並將該階段定調為提升效率的重要轉折。不過,相較當時因疫情後成長預期修正所引發的人事調整,此次裁員更偏向長期策略布局。 另外,為配合AI發展方向,Meta也同步調整內部資源配置。原隸屬元宇宙部門「Reality Labs」的部分團隊已被重新編組,轉往新成立的「Applied AI」部門,負責開發具備自動化執行與程式撰寫能力的系統。 針對相關裁員規劃,Meta目前尚未對外做出正式說明。  

Public opinion a factor in government’s decision to investigate officials: minister

Public opinion a factor in government’s decision to investigate officials: minister

Hong Kong authorities will take public opinion into account when deciding whether to trigger a new investigation mechanism to hold senior officials accountable, the city’s civil service minister has said. Permanent secretaries of bureaus, who are not covered by the proposed “Heads of Department Accountability System”, will also face scrutiny if they are found to

These Two Actors Are Early Favorites to Win 2027 Oscar for Best Lead Actor

It’s admittedly early to talk about the 2027 Oscars, but two stars are already predicted to be the main contenders for the Best Lead Actor award. For the 2026 Academy Awards, the battle for the Oscar in this category was difficult to predict. Timothée Chalamet’s performance in Marty Supreme was the early frontrunner before Sinners’

USD/CAD Extends Pullback to Three‑Week Lows Below 1.3700

USD/CAD Extends Pullback to Three‑Week Lows Below 1.3700

USD/CAD extends almost two-week losing streak, drops below 50‑day SMA. Elevated oil prices underpin the loonie, weighing on the pair. RSI and stochastics slip into negative territory. USD/CAD is extending its corrective decline from the year‑to‑date high of 1.3965 reached in late March, sliding for a fifth consecutive session and marking nine down days in

0
Would love your thoughts, please comment.x
()
x