Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

Git 的加入與提交機制(學習筆記二)

搞懂暫存區(staging area)與版本庫的關係,Git 就學會一半了。這篇筆記整理加入、提交與忽略的相關操作。

加入暫存

git add -i           # 互動模式加入
git add -p           # 互動模式的 patch 模式,逐段決定
git add somefile

提交

git commit -m "changes to somefile"
git commit -m "changes to somefile" -a
git commit -m "changes to somefile" somefile

加 -a 會自動把已追蹤檔案的修改一起提交,跳過 git add;指定檔名則只提交該檔。

自訂別名

git config --global alias.ci "commit"

之後 git ci 就等於 git commit。

查看差異

git diff            # 工作區 vs 暫存區
git diff --cached   # 暫存區 vs 版本庫
git diff HEAD       # 工作區 vs 版本庫

改名與刪除

git mv index.html hello.html

若不使用 git mv,就得手動 git add 新檔名再 git rm 舊檔名,兩步驟缺一不可,因為 Git 本身不記錄「改名」這個動作,它只記錄內容變化。

忽略檔案

版本庫層級的忽略規則寫在 .gitignore:

.*.swp

若只想在本地忽略、不想把規則提交上去,可編輯 .git/info/exclude,寫入同樣的內容即可。

Copyright © Linux教程網 All Rights Reserved