Command to open file with git

后端 未结 18 1286
滥情空心
滥情空心 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 04:44

    You can use the following commands to open a file in git bash:

    vi <filename>               -- to open a file
    
    i                           -- to insert into the file 
    
    ESC button followed by :wq   -- to save and close the file 
    

    Hope it helps.

    Any other terminal based text editor, like vim, nano and many will also do the job just fine.

    0 讨论(0)
  • 2021-01-30 04:46

    Git has nothing to do with how you open/edit files in your project. Configuring the editor in git is only so that git internal things that require an editor (commit messages for example) can use your preferred editor.

    If you just want to open files from the command line (cmd.exe) as if they were double clicked in the windows explorer, I think you can use start <filename>.

    0 讨论(0)
  • 2021-01-30 04:46

    I used Atom, to open files this works for me

    atom index.html
    

    Hopefully this helps.

    0 讨论(0)
  • 2021-01-30 04:54

    I was able to do this by using this command:

    notepad .gitignore
    

    And it would open the .gitignore file in Notepad.

    0 讨论(0)
  • 2021-01-30 04:55

    Maybe could be useful to open an editor from a script shared in a git repository, without assuming which editor could have anyone will use that script, but only that they have git.

    Here you can test if editor is set in git config, and also open files not associated with that editor:

    alias editor="$(git config core.editor)"
    if [ "$(alias editor | sed -r "s/.*='(.*)'/\1/")" != "" ]; then
        editor <filename>
    else
        start <filename>
    fi
    

    Works great with my .gitconfig on windows:

    [core]
        editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin
    
    0 讨论(0)
  • 2021-01-30 05:00

    You must have an application associated with the file type. You must be in the folder that houses the file. In gitbash: start file.extension

    0 讨论(0)
提交回复
热议问题