Git總結

commit

HEAD: 當前commit

HEAD~1: 簡寫HEAD~, HEAD的前一個版本

HEAD~n: HEAD的前n個版本

HEAD^1: 簡寫HEAD^, 只merge時主分支

HEAD^2: 代指merge分支

branch

branch_name: 本地某個分支

origin/branch_name: 遠程本地對應分支

git branch: 創建分支

git checkout: 切換分支

git checkout -b: 創建並切換分支

三個分區

工作區working dirctory

暫存區 stage index

歷史記錄區 history

fetch

git fetch branch-name: 更新遠程跟蹤分支,從遠程copy到本地refs/remotes/origin命名空間中去

merge

git merge other-branch: 將其他分支合併到當前分支

pull

git pull branch-name: git fetch+merge, 更新遠程跟蹤分支,並將其merge到當前分支

rebase

git rebase develop: 將develop放入臨時分支,將當前分支commit以patch的形式追加到develop臨時分支

git rebase -i develop: 交互的方式rebase

git rebase --abort: 終止rebase,回到當前分支初始狀態

git pull --rebase origin develop: 拉取遠程develop更新,基於最新develop rebase

reset

git reset --hard commit-id: 將版本庫回退到指定commit-id,同時將暫存區、工作區內容都重置成commit-id這個版本,因此會丟失暫存區/工作區的修改

git reset --soft commit-id: 將版本庫回退到指定commit-id,將commit-id之後的變更移動到staging區,保留staging,working區

revert

git revert commit-id: 新增一個commit回滾之前的commit-id, 是之前commit-id的逆向操作

cherry-pick

git cherry-pick commit-id: 將某個commit-id合併到當前分支

log

git log: 查看提交記錄

git log -p: 按補丁格式顯示提交中差異

git log --stat: 顯示每次commit的統計信息

git log --pretty: 格式化顯示提交信息

git reflog: 查看所有操作記錄,包過被刪除的commit

case

遠程覆蓋本地:

git fetch --all

git reset --hard origin/branch_name

本地覆蓋遠程:

git push --force origin

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章