Making git auto-commit

前端 未结 18 1813
面向向阳花
面向向阳花 2020-11-27 08:41

I\'d like to use git to record all the changes to a file.

Is there a way I can turn git \'commit\' on to automatically happen every time a file is updated - so ther

18条回答
  •  不知归路
    2020-11-27 09:27

    I wanted to do this in windows, and found the best way was to use Directory Monitor to check for changes then when it detected a change have it run:

    Program: cmd.exe

    Params: /C C:\pathToBatchFile.bat

    That batch file contained:

    c:
    cd c:\gitRepoDirectory\
    (if exist "%PROGRAMFILES(X86)%" (
    "%PROGRAMFILES(X86)%\git\bin\sh.exe" --login -i -c "git commit -am AutoCommitMessage"
    ) else (
    "%PROGRAMFILES%\git\bin\sh.exe" --login -i -c "git commit -am AutoCommitMessage"
    ))
    

    I also tried having another command in there to add files ("%PROGRAMFILES(X86)%\git\bin\sh.exe" --login -i -c "git add *.*"), but I don't think I got that working properly.

    I also made a post-commit hook containing:

    #!/bin/sh
    git.exe pull -v --progress  "origin"
    git.exe push    --progress  "origin" master:master
    curl.exe -s https://webserverdomain.com/updateFromGitHook.x?r=repoName
    

    (If there were any conflicts then it would abort the pull and abort the push, but there wasn't any clear way to tell that had happened - in the end we abandoned the whole idea because of this one flaw.)

    That curl command told my server that it needed to do a pull on the code. All that was needed to handle it in php was:

    
    

    The only problem with that was it needed to be run by the root user instead of the apache user, so I also had to make a file in /etc/sudoers.d/ containing:

    www-data ALL = NOPASSWD: /usr/bin/git
    

    For me, I think that worked pretty solidly. Directory Monitor can be configured to run on startup and start minimized, and it can watch several different folders

提交回复
热议问题