Git常用指令

2021-09-12 23:10:22 字數 1802 閱讀 1801

git status:提交前先檢查下修改了什麼內容,當前git目錄下各檔案的狀態

git commit:提交修改

git commit -m 「add readme」 新增備註

git commit -a 跳過stage快取區,直接提交當前目錄下的所有修改

git push 遠端主機名 本地分支名 遠端分支名:將本地分支推到遠端分支

git push origin --delete 分支名 刪除遠端分支

git log:提交歷史檢視

git reflog 檢視所有分支的所有操作記錄

git branch:顯示當前所有分支

git branch -vv:檢視當前的本地分支與遠端分支的關聯關係

git checkout -b testing:建立testing 分支並且切換testing分支

git branch testing # 建立testing 分支

git checkout testing # 切換到testing分支

git merge hotfix:分支合併

git checkout master 將hotfix分支合併到master(主分支)上

git merge hotfix

git branch -d hotfix:刪除分支

重置源檢視源 git remote -vv

刪除源 git remote rm origin

新增源 git remote add origin 源位址

將遠端git倉庫裡的指定分支拉取到本地(本地不存在的分支)

git checkout -b 本地分支名 origin/遠端分支名

遠端主機的版本庫有了更新,全部取回本地

git fetch

遇到忘記pull**,直接commit時,先pull**,有衝突解決衝突,然後commit**,最後push

不小心commit**,想要撤回**時,先git log,然後 git reset --hard 剛剛提交的錯誤commit_id

遇到合併提交時,先git log —oneline -最近提交次數,然後git cherry-pick commit_id撤回提交, git log,git reset --hard commit_id,git push -f origin master(強制提交)

git checkout -b fix-bug建立+切換分支

git branch -vv檢視當前的本地分支與遠端分支的關聯關係

git push origin fix-bug將本地新建分支push到自己的本地遠端origin上

git branch --set-upstream-to=origin/fix-bug把本地分支與遠端origin的分支進行關聯處理(通過 --set-upstream-to 命令)

git pull:相當於是從遠端獲取最新版本並merge到本地

git fetch:相當於是從遠端獲取最新版本到本地,不會自動merge

Git 常用指令

首先需要建立乙個repo,這是cd到資料夾底下,然後init。git init 在檔案系統裡面的檔案如果不新增到git的repo裡面,不會自動被git辨識,需要手動新增,這也是初始化repo是必須要做的事。git add documentation txt git add git sh 刪除檔案,分...

git常用指令

git 常用命令 git init here 建立本地倉庫 repository 將會在資料夾下建立乙個 git 資料夾,git 資料夾裡儲存了所有的版本資訊 標記等內容 git remote add origin git github.com winter1991 helloworld.git 把...

git常用指令

git config global user.name robbin git config global user.email fankai gmail.com git config global color.ui true git config global alias.co checkout g...