Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Git 基本指令速查:從 clone 到分支合併

以下把日常開發最常回頭查的 Git 指令整理成清單:

1、複製專案到本地:git clone xxxxx

2、建立分支:git checkout -b xxx(建立並切換)或 git branch xxx

3、推送分支到遠端:git push origin xxx

4、查看本地分支:git branch;查看遠端分支:git branch -a

5、切換分支:git checkout xxx

6、查看狀態:git status

7、提交檔案:git add → git commit -m "註釋" → git push

8、推送並建立追蹤:git push --set-upstream origin xxx

9、歷史紀錄與回滾:

git log
git log --pretty=oneline
git reflog
git reset --hard 2f46641   # 回滾到指定版本

10、比較差異:git diff HEAD -- 檔案

11、撤銷工作區修改:git checkout -- 檔案

12、刪除/恢復檔案:git rm 檔案;未提交前恢復:git checkout origin/master -- README.md

13、合併分支:git merge dev

分支常用指令總整理:

git branch              # 查看分支
git branch <name>       # 建立分支
git checkout <name>     # 切換分支
git checkout -b <name>  # 建立+切換
git merge <name>        # 合併到目前分支
git branch -d <name>    # 刪除分支

14、遇到提交衝突時,Git 無法自動合併,必須先手動解決衝突再提交。可用 git log --graph --pretty=oneline --abbrev-commit 查看分支合併圖。若不想讓某檔案被納入版控,可寫進 .gitignore,或用 git update-index --assume-unchanged 檔案、git rm --cached 檔案 取消追蹤。

Copyright © Linux教程網 All Rights Reserved