Git 以及 Vim 常見命令整理

Vim 常見的命令

  1. 'i'進入編輯模式
  2. 'esc'進入命令模式
  3. ':wq'保存退出
  4. 'q!'不保存強制退出

Git命令

git命令.peng

除了以上列出的常用的命令外,下面著重結(jié)合場景來說明一下git rebase命令

合并本地多個commit

同個功能因一些原因打斷開發(fā),且并沒有開發(fā)完成,此時可能會先提交一個備份的commit,為了提交簡潔,需要將備份的提交合并到一起。此時就會用到git rebase -i命令

冗余提交.jpg

然后我們執(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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容