創建(克隆)倉庫
-
克隆倉庫
git clone 倉庫地址
-
創建倉庫
git init
工作空間操作
- 查看本地狀態
git status
- 查看文件差異修改
git diff
- 添加當前所有修改準備提交
git add .
- 添加跟蹤文件中的修改準備提交
git add -p <file>
- 提交所有更改的文件
git commit -a
- 提交準備提交的文件
git commit
- 修改最後一次提交描述
git commit --amend
提交歷史
- 顯示所有的提交
git log
- 顯示特定文件的隨時間的變化
git log -p <file>
- 查看某個文件都有誰修改過
git blame <file>
分支&標籤
- 顯示所有的分支
git branch -av
- 切換分支
git checkout <branch>
- 基於遠程分支創建新的跟蹤分支
git checkout --track <remote/branch>
- 刪除分支
git branch -d <branch>
- 當前提交分支添加標籤
git tag <tag-name>
更新&推送
- 列出所有當前配置的遠程操作
git remote -v
- 顯示關於遠程的信息
git remote show <remote>
- 添加新的遠程倉庫
git remote add <shortname><url>
- 下載所有的更新,但不合併到工作空間
git fetch <remote>
- 下載所有的更新,合併到工作空間
git pull <remote><branch>
- 推薦本地修改到遠程
git push <remote><branch>
- 刪除遠程的分支
git branch -dr <remote/branch>
- 推送添加的標籤信息
git push --tags
合併&重置
- 合併分支
git merge <branch>
- 變基(衍合)
git rebase <branch>
- 中止變基
git rebase --abort
- 在解決衝突之後繼續重新開始變基
git rebase --continue
- 使用配置的合併工具解決衝突
git mergetool
- 添加和移除跟蹤文件
git add <file>
git rm <file>
回退
- 丟棄工作目錄中的所有本地更改
git reset --hard HEAD
- 丟棄特定文件中的本地更改
git checkout HEAD <file>
- 恢復提交
git revert <commit>
- 回退之前的提交,丟棄所有的更新
git reset --hard <commit>
- 回退之前的提交,並將所有更改保留爲未分級更改
git reset <commit>
- 回退之前的提交,保留未提交的本地更改
git reset --keep <commit>