美文网首页
Git 以及 Vim 常见命令整理

Git 以及 Vim 常见命令整理

作者: Bear_android | 来源:发表于2019-06-11 17:22 被阅读0次

    Vim 常见的命令

    1. 'i'进入编辑模式
    2. 'esc'进入命令模式
    3. ':wq'保存退出
    4. 'q!'不保存强制退出

    Git命令

    git命令.peng

    除了以上列出的常用的命令外,下面着重结合场景来说明一下git rebase命令

    合并本地多个commit

    同个功能因一些原因打断开发,且并没有开发完成,此时可能会先提交一个备份的commit,为了提交简洁,需要将备份的提交合并到一起。此时就会用到git rebase -i命令

    冗余提交.jpg

    然后我们执行

    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。

    # 主分支: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 push -f
    

    相关文章

      网友评论

          本文标题:Git 以及 Vim 常见命令整理

          本文链接:https://www.haomeiwen.com/subject/tyxcfctx.html