How to detach “git gui” started in “Git bash” on Windows?

后端 未结 5 1572
南笙
南笙 2021-02-06 05:22

For example,

  1. I start \"git bash\";
  2. I navitage to certian directory;
  3. I start git gui&;
  4. I close the console window or pre
相关标签:
5条回答
  • 2021-02-06 05:59

    If the gitgui is already started, you can disown the job so that it doesn't end with the console:

    disown -h <jobid>
    

    If you want to do it when you start Git GUI (so you just launch and forget) there is nohup but for an unknown reason it's not in the binaries distributed by MsysGit

    0 讨论(0)
  • 2021-02-06 06:06

    To the benefit of the others I will give a more general answer related to both git bash and msys bash.

    Solution 1: Detach without stdout

    Assume you want to detach the app:

    "C:\Program Files\MyApp\MyApp.exe"
    

    which does not output any info you want to retrieve to stdout (or stderr).
    use in your Windows bash shell:

    cmd //c start //D "C:\\Program Files\\MyApp"  MyApp.exe arg1 arg2 
    

    MyApp will run in a separate window and closing the calling bash shell will not affect it (by and large like a Linux daemon).

    As noted, you can't read app messages unless they are dialog messages, therefore this solution fits to GUI applications. Anyway, if MyApp.exe is instead a Windows batch file like MyApp.cmd, it will call its cmd.exe host and log there: in short you will read outputs for the .cmd/.bat case.

    Mac-like users

    The cmd.exe window will flash-out for an instant. If this is not such cool for you(r users), in the above line replace cmd with cmdow, NirCmd or the likes.

    Solution 2: Detach with stdout

    If you want to read logs to stdout and stderr, use:

    cmd //c start cmd //k  "C:\\Program Files\\MyApp\\MyApp" arg1 arg2 
    

    This alternative is mostly advised if MyApp is a console application. Now you get a daemon with a "home". MyApp will run hosted by the second cmd.exe and you will see here its output.
    For a GUI app you end out with two windows: MyApp window and the calling cmd window.

    In both cases, exiting MyApp doesn't mean closing the cmd window; while closing the cmd window will only close MyApp console.

    If the flashing punch strikes you, here you only need to replace the first cmd, the second is your daemon's visbile home.

    Solution 3: Detach document centric applications

    Some documents are closely related to some processing applications, via a mechanism resembling the Linux shebang syntax, but based on Windows' registry; so you open the document without calling the related application.

    This behaviour can be emulated in bash and even in a detached style.

    As for apps not needing to output to stdout and stderr, opening MyApp.doc with:

    cmd //c start //D "C:\\Program Files\\MyApp"  MyApp.exe  "Path\\to\\MyApp.doc"
    

    can be simplified to:

    cmd //c start //D "Path\\to" MyApp.doc
    

    As for apps needing stdout and stderr output,

    cmd //c start cmd //k  "C:\\Program Files\\MyApp\\MyApp" "Path\\to\\MyApp.doc"
    

    can be reduced to:

    cmd //c start cmd //k  "Path\\to\\MyApp.doc"
    
    0 讨论(0)
  • 2021-02-06 06:16

    The following command works for me from "git bash":

    git gui </dev/null >/dev/null 2>&1 &
    

    I tried Ctrl+C, Ctrl+D and simply closing the console window. git gui stayed open in all cases.

    0 讨论(0)
  • 2021-02-06 06:18

    In Git for Windows 2.25, simply typing

    git-gui
    

    opens the GUI for the current working directory, completely detached. (Note the hyphen).

    0 讨论(0)
  • 2021-02-06 06:22

    Based on Antonio's answer I have figured out the following recipe:

    cmd //c start //D "C:\Program Files\Git\bin" "wish.exe" "C:\Program Files\Git\libexec\git-core\git-gui"
    

    It works, as can be tested by pressing Ctrl-D in the shell. The shell closes properly and git gui continues to work.

    Drawback: this solution ignores the current directory and opens git gui in the C:\Program Files\Git\bin directory, not in the current directory.

    One may argue that git gui on Windows remembers recent repositories so it's only a click away. True, but the question is: how to get a detached git gui in the current directory...

    I have tried a few variants to fix the drawback, but nothing truly satisfying.

    The ones below always ask what to open git gui with. Choosing "C:\Program Files\Git\bin\wish.exe" in the file selector works but has to be done every time.

    cmd //c start //D "E:\\escapedwindowsstyle\\path\\to\\my\\git\\repo\\" "C:\\Program Files\\Git\\bin\\wish.exe" "C:\\Program Files\\Git\\libexec\\git-core\\git-gui"
    
    cmd //c start "C:\\Program Files\\Git\\bin\\wish.exe" "C:\\Program Files\\Git\\libexec\\git-core\\git-gui"
    

    Can anyone understand what happens and/or improve on that ?

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