代码之家  ›  专栏  ›  技术社区  ›  Justin Force jmbucknall

在新的vim窗口中写入git commit消息,然后在vim中全部提交

  •  3
  • Justin Force jmbucknall  · 技术社区  · 14 年前

    我有这些git的vim映射。下面的大多数命令都有效,但最后一个命令, G ,根本不起作用。我想打开一个新的VIM(最好是已经加载了git提交消息模板,根据默认的终端行为),编辑并保存我的消息,然后提交。

    有没有其他方法来解决这个问题?

    " git shortcuts
    "" show diff in new window
    if has("gui_running")
      noremap gd :!git diff <BAR> gvim -<CR><CR>
    else
      noremap gd :!git diff <BAR> vim -<CR><CR>
    endif
    noremap gs :!git status<CR>
    noremap ga :!git add %<CR>
    "" edit commit message in new window
    if has("gui_running")
      noremap gm :!gvim __vim_gitcommitmessage && git commit -F __vim_gitcommitmessage && rm __vim_gitcommitmessage<CR>
    else
      noremap gm :!vim __vim_gitcommitmessage && git commit -F __vim_gitcommitmessage && rm __vim_gitcommitmessage<CR>
    endif
    

    更新:

    根据VONC的建议,我现在使用 fugitive.vim . 我替换了以前的vim绑定,并将此插件推荐给任何使用vim和git的人。

    " fugitive shortcuts
    noremap ggs :Gstatus<cr>
    noremap ggc :Gcommit<cr>
    noremap gga :Gwrite<cr>
    noremap ggl :Glog<cr>
    noremap ggd :Gdiff<cr>
    
    2 回复  |  直到 14 年前
        1
  •  4
  •   VonC    14 年前

    Vim有一些Git包装脚本,这些脚本封装了常见的Git命令,并允许通过临时缓冲区提交:

    一个能满足这个要求的方案是 fugitive.vim its doc :

    :MinSCMCommitTracked[!]         (Default mapping: \s<C-c>)
    

    打开临时缓冲区以输入提交消息。写入提交缓冲区,并提交所有跟踪的文件。

                Used SCM commands ~
                hg  : commit
                git : commit -a
                bzr : commit
    
    :MinSCMCommitAll[!]             (Default mapping: \sc)
    

    打开临时缓冲区以输入提交消息。写入提交缓冲区,并提交当前存储库工作目录中的所有文件。

    此命令与将未跟踪文件添加到当前存储库中的:minscmccommittracked不同。

                Used SCM commands ~
                hg  : commit -A
                git : add -a && commit -a
                bzr : add && commit
    

    源代码是可用的,您可以在自己的VIM脚本中重用所需的部分。

        2
  •  1
  •   Cascabel    14 年前

    编辑一个文件,然后告诉Git将其用作提交消息,这到底有什么意义?为什么你不能用正常的运行模式? git commit ,让它产生vim,编写消息,保存并退出提交?或者如果你需要一个模板, git commit -e -F <template file> .