Vim 常見的命令
- 'i'進入編輯模式
- 'esc'進入命令模式
- ':wq'保存退出
- 'q!'不保存強制退出
Git命令
除了以上列出的常用的命令外,下面著重結(jié)合場景來說明一下git rebase
命令
合并本地多個commit
同個功能因一些原因打斷開發(fā)孝鹊,且并沒有開發(fā)完成别智,此時可能會先提交一個備份的commit
,為了提交簡潔赚窃,需要將備份的提交合并到一起。此時就會用到git rebase -i
命令
然后我們執(zhí)行
1. 執(zhí)行下面命令(表示合并最近的3次提交)
git rebase -i HEAD~3
2.之后會出現(xiàn)洗面的vim編輯器
pick 9ce5910 tranform to kotlin #
pick 5340ce6 整理狼人殺模塊岔激,重構(gòu)狼人殺主界面
pick a977304 MVVM模式重構(gòu)狼人殺頁面
# Rebase 76ce1a8..a977304 onto 76ce1a8 (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
3. 鍵盤點擊 i 進入編輯模式勒极,按照提示修改第二三次提交的pick為 s(包含) 或者 f。這里不需要提交信息所以改為s
pick 9ce5910 tranform to kotlin #
f 5340ce6 整理狼人殺模塊虑鼎,重構(gòu)狼人殺主界面
f a977304 MVVM模式重構(gòu)狼人殺頁面
# Rebase 76ce1a8..a977304 onto 76ce1a8 (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
-- INSERT --
4.點擊esc辱匿,進入vim命令模式,然后輸入":wq"回車 炫彩。
保持主分支線性
有時我們同一個版本會有多個分支同時開發(fā)匾七,如果采用pull + merge的方式會產(chǎn)生多余的提交記錄影響。此時我們依然可以采用git rebase江兢。
# 主分支:dev 功能分支: feature
1. 切換到主分支
git checkout dev
2. 查看主分支是否是最新的
git fetch
git status
3. 如果不是最新的
git pull
4. 切回功能分支
git checkout -
5. rebase 主分支
git rebase -i dev
6. 同第一種合并多個commit場景進行vim操作
7. 如果存在沖突昨忆,需要解決沖突后
git rebase --continue
7. rebase成功后,需要強推回自己的遠(yuǎn)程分支(此處注意如果有沖突建議新建一個分支去操作杉允,保存好代碼防止異常出現(xiàn))
git push -f