代碼提交
- 回退到某個版本: git reset XXX(commit的id)
- 生成新的changeID:git commit --amend(針對gerrit,abandon後,再次提交須要生成新的changeId)
- 拉取代碼:git pull --rebase
- 添加到暫存區:git add .
- 提交commit:git commit -am XXXX(備註信息)(防止出現衝突和merge的狀況,先git pull --rebase再commit)
- push到遠程:git push origin HEAD:refs/for/branchName
多條commit合成一條commit
git rebase -i commitId(你想要合併的幾個commitId的以前的commitId)git
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
查看log,已經變成一條commitoop
分支的操做
- 新建一個分支,並切換到該分支: git checkout -b branchName(分支名)
- 推到遠程分支:git push origin -u branchName(分支名)
- 切換分支/切換上一個分支:git branch -
- 刪除本地分支:git branch -D branchName(分支名)
- 不當心刪除了遠程分支(本地分支還木有刪除): git push origin branchName:branchName
stash
- 保存暫存區和工做區的工做進度:git stash save XXXX(進度的信息,好比修改樣式)
- 查看stash list:git stash list
- 獲取stash list的某一個到工做區(並在list刪除):git stash pop stash@{2}
- 獲取stash list的最後保存(第一個)到工做區(並在list刪除):git stash pop
合併代碼
1.(commit較少時,cherry-pick合併到dev)spa
- checkout dev
- git pull --rebase
- git cherry-pick commitID
- 若是是圖片衝突git checkout --ours .來解決衝突保留本來的,git checkout --theirs . (傳進來的)
- 若是代碼有衝突,編譯器解決衝突後,git add .
- git cherry-pick --continue
- 若是想放棄合併:git cherry-pick --abort
2.(commit較多時,rebase合併到dev)blog
- checkout dev
- git pull --rebase
- git rebase -i branchName
- 清除光標以前的全部提交記錄:gg+d+G
- noop
- git pull --rebase
- 若是不是你想合併的commit,能夠忽略:git rebase --skip
- 若是有衝突,解決衝突,git add .
- git rebase --continue
- 直到全部的都rebase完