版本歷史小技巧

Git 入門

George Boorman

Curriculum Manager, DataCamp

專案會成長!

  • 專案越大=提交越多=輸出更長

 

顯示雜湊與日誌訊息的八個提交示意圖

Git 入門

限制提交數量

  • 你可以用 - 限制顯示的提交數:

  • 僅顯示最近 3 次提交

    git log -3
    
Git 入門

限制到特定檔案

  • 只看某個檔案的提交歷史:
git log report.md
Git 入門

技術組合應用

cd data
git log -2 mental_health_survey.csv
Git 入門

git log 輸出

commit f35b9487c063d3facc853c1789b0b77087a859fa
Author: Rep Loop <[email protected]>
Date:   Fri Jul 26 15:14:32 2024 +0000

    Add two new participants' data.

commit 7f71eadea60bf38f53c8696d23f8314d85342aaf
Author: Rep Loop <[email protected]>
Date:   Fri Jul 19  09:58:21 2024 +0000

    Adding fresh data for the survey.
Git 入門

自訂日期區間

  • 依日期篩選 git log
git log --since='Month Day Year'
  • 自 2024 年 4 月 2 日以來的提交:
git log --since='Apr 2 2024'
  • 介於 4 月 2 日到 11 日的提交:
git log --since='Apr 2 2024' --until='Apr 11 2024'
Git 入門

可接受的篩選格式

自然語言

  • "2 weeks ago"
  • "3 months ago"
  • "yesterday"

日期格式

  • "07-15-2024"
    • 建議用 ISO 格式 "YYYY-MM-DD"
    • 檢查系統設定是否相容,例如 12-06-2024 可能是 6th Dec12th June
  • "15 Jul 2024""15 July 2024"
    • 無效:"15 Jul, 2024"
1 https://www.iso.org/iso-8601-date-and-time-format.html
Git 入門

尋找特定提交

git log
  • hash 只需前 8–10 個字元
git show c27fa856
Git 入門

git show 輸出

git show 輸出:上方為 git log,下方為 git diff,底部標出錯誤的資料輸入

Git 入門

一起來練習吧!

Git 入門

Preparing Video For Download...