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

簡明 Git 命令速查表(中文版)

這是一份方便隨時查閱的 Git 命令速查表,涵蓋從建立倉庫到撤銷操作的常用指令。

簡明 Git 命令速查表(中文版)

創建

git clone ssh://user@domain.com/repo.git   複製倉庫
git init   建立本地倉庫

本地修改

git status   顯示已修改檔案
git diff   顯示與上次提交的差異
git add   加入所有修改到下次提交
git add -p <file>   選擇性加入
git commit -a   提交所有修改
git commit -m '訊息'   附加訊息提交
git commit --amend   修改上次提交(勿改已發布記錄)

搜索

git grep "Hello"   搜尋文本
git grep "Hello" v2.5   在指定版本搜尋

提交歷史

git log   顯示所有提交
git log --oneline   精簡顯示
git log --author="username"   顯示某用戶提交
git log -p <file>   顯示檔案修改
git blame <file>   逐行標註修改者

分支與標籤

git branch   列出分支
git checkout <branch>   切換分支
git checkout -b <branch>   建立並切換
git branch --track   建立可追溯分支
git branch -d <branch>   刪除本地分支
git tag <tag-name>   打標籤

更新與發布

git remote -v   列出遠端
git remote add   新增遠端
git fetch   下載不合併
git pull origin master   下載並合併
git push   發布到遠端
git push --tags   發布標籤

合併與重置

git merge <branch>   合併到 HEAD
git rebase <branch>   重構基線(勿重置已發布提交)
git rebase --abort   退出重置
git rebase --continue   解決衝突後繼續
git mergetool   用工具解決衝突

撤銷

git reset --hard HEAD   放棄所有修改
git reset HEAD   撤銷上次 add
git checkout HEAD <file>   放棄單一檔案修改
git revert <commit>   建立反向新提交
git reset --hard <commit>   重置並丟棄後續修改
git reset --keep <commit>   重置並保留本地修改

這份速查表涵蓋了日常開發最常用的 Git 指令,建議收藏以備不時之需。

Copyright © Linux教程網 All Rights Reserved