Command to open file with git

后端 未结 18 1317
滥情空心
滥情空心 2021-01-30 04:05
  • I have sublime text as the default editor in git (and it works)
  • git config --edit opens the config file in sublime text (Awesome)
18条回答
  •  醉酒成梦
    2021-01-30 05:03

    I know this is ancient, but I need to do this at the end of a git helper script (alias that creates aliases from a template), and found what I think is the real answer:

    There is a porcelain-ish helper called git-sh-setup that, when sourced, gives you a git_editor function that

    runs an editor of user’s choice (GIT_EDITOR, core.editor, VISUAL or EDITOR) on a given file, but error out if no editor is specified and the terminal is dumb.

    The git-sh-setup documentation description basically tells you not to use it, and that's probably good advice in this case.

    Fortunately, the git-sh-setup is a shell script and the git_editor portion of it is pretty small, and we can just copy that:

    git_editor() {
        if test -z "${GIT_EDITOR:+set}"
        then
            GIT_EDITOR="$(git var GIT_EDITOR)" || return $?
        fi
        eval "$GIT_EDITOR" '"$@"'
    }
    

    You should be able to put that in your own scripts or turn it into a bash alias and then call it like git_editor file1.txt file2.txt ...

提交回复
热议问题