Git

建立日期:2025-09-28



Git 輕鬆上手

Git
Git

今天老師要求期末前每個小組需要繳交 50 頁的書面報告,回到家裏每個同學就像發了瘋似的猛讀文獻,他們選了一個同學作為他們的組長。只要每個人想要更新他們所寫的內容,都需要知會組長,估計還沒到學期末組長還沒有瘋掉,組員也差不多要被送走了。這麼多不同的版本,作為組長要把每部份處理好,只要內容多起來想必是難如登天的事情。

很幸運地,這群人非常的堅強,他們成功熬過寫報告的日子了。要繳交報告前,組長的桌面有這些檔案:

  • report.docx
  • report1.docx
  • report2.docx
  • report_final.docx
  • report_real_final.docx
  • report_hand_in_ver.docx
  • report_hand_in_ver1.docx
  • report_hand_in_ver2.docx
  • report_hand_in_ver3.docx
  • report_0929_ver.docx
  • report_0930_revised.docx
  • reprot_revised_done.docx

很明顯,這裏所有的檔案全部都是一個即將要繳交的檔案,只是它經歷了非常多的修改版本。成功繳交是一回事,如果老師覺得同學們應該要寫的更好而選擇退回作業呢,我應該要怎麼在那麼多的檔案中找到差異,修改並且繳交最終的版本?

在這個情境中已經出現了一些問題:

  • 每個同學都必須與組長溝通,如果組長身體不適的那幾天,整理報告這件事就癱瘓了。
  • A 同學自己的桌面可能就一大堆 A_report1.docx、A_report2.docx、A_report111.docx、A_report0909.docx、A_report1001.docx… 這部分很明顯也是同一份文件的不同版本,命名無法完全看出版本先後順序。
  • 組長的桌面亦是如此,也不確定到底在「什麼時候」合併了「哪些同學」的「哪些內容」。
  • 每個版本迭代都會有差異,如果要比較不同版本的差異需要開兩個視窗人工核對,將不一樣的地方用不同顏色註記。
  • 同學沒辦法隨時看到處理完的完整版報告內容。

為什麽要使用 Git

我們先講個小故事:

創造 Linux 系統的上帝 Linus Torvalds 也創造了 Git。 在 2002 至 2005 年間 Linus 使用 BitKeeper 作為管理 Linux kernel 的程式碼版本控制工具,後來,BitKepper 收回了給 Linus 與其 Linux Kernel 開發團隊的免費軟體授權。Linus 一氣之下花費了 10 天的時間寫了另外一個程式碼版本控制的工具 aka Git。

Git 到底是什麼意思?Git 原始碼的 README.md

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you’re in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks