介紹
分布式:
三個(gè)區(qū)域:
基礎(chǔ)
創(chuàng)建本地倉:git init
克隆倉庫:git clone?
? ? ? 例子:git clone https://github.com/xxx/xxx.git
獲取遠(yuǎn)程分支代碼:git fetch
? ? ? 例子:git fetch origin master
同步遠(yuǎn)程分支代碼(fetch+merge):git pull
? ? ? 例子:git pull origin master
添加到本地緩存區(qū):git add
? ? ? 例子:git add xxx.java
從本地緩存區(qū)刪除:git reset HEAD
? ? ? 例子:git reset HEAD xxx.java
提交到本地倉:git commit
? ? ? 例子:git commit -m "Fix bug xxx, by xxx"
將本地倉的提交同步到遠(yuǎn)程倉:git push
? ? ? 例子:git push origin master
查看當(dāng)前狀態(tài):git status
查看提交記錄:git log
進(jìn)階
查看本地分支:git branch
查看遠(yuǎn)程分支:git branch -r
查看所有分支:git branch -a
切換分支:git checkout
? ? ? 例子:git checkout branch_xxx
創(chuàng)建本地分支:git branch xxx
? ? ? 例子:git branch local_branch_xxx
合并某分支到當(dāng)前分支:git merge
? ? ? 例子:git merge master
將修改放入抽屜:git stash
從抽屜中拿出改動(dòng):git stash pop
查看抽屜記錄:git stash list
從抽屜中拿出某次記錄:git stash pop xxx
? ? ? 例子:git stash pop stash@{0}
還原到某次提交的狀態(tài):git reset
? ? ? 例子:git reset --hard xxxxxxxxxxxxxxxxxxxxxxxxxxx
同步代碼并且將本地提交推到最新(保證遠(yuǎn)程庫提交順序不變):git pull --rebase
? ? ? 例子:git pull origin master --rebase
其他
打標(biāo)簽:git tag
? ? ? 例子:git tag version_xxx
查看reset緩存區(qū)(誤操作恢復(fù)):git reflog
本地分支替換遠(yuǎn)程分支(多用于遠(yuǎn)程分支回退某次提交):git push origin +branch_xxx:branch_xxx
? ? ? 例子:git push origin +master:master
查看幫助:git help
查看配置:git config