Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 電腦軟體介紹

Git 新手兩分鐘入門:個人項目版本控制極簡指南

編輯:電腦軟體介紹

適用場景:單人項目、定期備份硬碟、無需遠端協作

無需伺服器,本地即可完整受益於版本控制:回退錯誤、對比差異、大膽實驗。以下為最小可用命令集。

初始化與提交

# 進入專案根目錄
git init

# 追蹤檔案(單檔/多檔/全目錄)
git add   ...
git add .          # 當前目錄所有檔

# 提交變更(附帶描述訊息)
git commit  ... -m "提交說明"
git commit -a -m "所有變更檔案的說明"

查看歷史與版本標識

# 精簡單行輸出:hash + message
git log --pretty=oneline

# 輸出指定檔案歷史
git log --pretty=oneline -- 

輸出範例:

dbe28a0a1eba45d823d309cc3659069fc16297e3 4th version
13bbf385e6d1f94c7f11a4cdfa2a7688dfdd84f8 3rd
a1696f671fb90dc8ea34645a6f851d0ab0152fc2 2nd
179e59467039c7a7b81f676297415c8e018542a0 first version

回退與對比

# 回退指定檔案到某版本(hash 前幾碼即可)
git checkout  -- 
# 例:git checkout 179e59467039 -- myfile

# 對比當前版本與歷史版本
git diff  -- 

# 對比兩個歷史版本
git diff   -- 

可選進階:.gitignore 過濾雜訊

專案根目錄建立 .gitignore,內容例:

*.pyc           # Python 編譯快取
__pycache__/    # Python 3 快取目錄

讓 git status 輸出乾淨,聚焦核心代碼變更。

Git指令速查表 git init git add git add . git commit git commit -a git log --pretty=oneline log輸出範例 git log git log -- filename git checkout checkout範例 git diff git diff 兩版本 git status .gitignore範例 .gitignore目錄忽略

掌握這 10 條命令 + .gitignore,即擁有「時光機」:隨時回退、對比、釋放實驗勇氣。團隊協作、分支、遠端推拉請進階至「五分鐘教程」或官方文檔。

Copyright © Windows教程網 All Rights Reserved