Git 以及 Vim 常見命令整理

Vim 常見的命令

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

Git命令

git命令.peng

除了以上列出的經常使用的命令外,下面着重結合場景來講明一下git rebase命令git

合併本地多個commit

同個功能因一些緣由打斷開發,且並無開發完成,此時可能會先提交一個備份的commit,爲了提交簡潔,須要將備份的提交合併到一塊兒。此時就會用到git rebase -i命令shell

冗餘提交.jpg

而後咱們執行vim

1. 執行下面命令(表示合併最近的3次提交)
git rebase -i HEAD~3

2.以後會出現洗面的vim編輯器

pick 9ce5910 tranform to kotlin #
pick 5340ce6 整理狼人殺模塊,重構狼人殺主界面
pick a977304 MVVM模式重構狼人殺頁面

# 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 整理狼人殺模塊,重構狼人殺主界面
f a977304 MVVM模式重構狼人殺頁面   

# 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"回車 。
複製代碼

保持主分支線性

有時咱們同一個版本會有多個分支同時開發,若是採用pull + merge的方式會產生多餘的提交記錄影響。此時咱們依然能夠採用git rebase。bash

# 主分支: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成功後,須要強推回本身的遠程分支(此處注意若是有衝突建議新建一個分支去操做,保存好代碼防止異常出現)
git pull -f
複製代碼
相關文章
相關標籤/搜索