Jes*_*erE 119
在Linux上,您可以使用inotifywait在每次更改文件内容时自动执行命令.
编辑:以下命令在保存后立即提交file.txt:
inotifywait -q -m -e CLOSE_WRITE --format="git commit -m 'autocommit on change' %w" file.txt | sh
Run Code Online (Sandbox Code Playgroud)
Les*_*uck 48
早期的inotifywait答案很棒,但它不是一个完整的解决方案.如上所述,它是一次性提交文件中的一次性更改.它不适用于编辑文件创建具有原始名称的新inode的常见情况. inotifywait -m显然遵循inode文件,而不是名称.此外,在文件更改后,如果没有git add或git commit -a,则不会为git commit 暂存.做一些调整,这是我在Debian上用来跟踪我的日历文件的所有更改:
/etc/rc.local中:
su -c /home/<username>/bin/gitwait -l <username>
Run Code Online (Sandbox Code Playgroud)
的/ home/<用户名>/bin中/ gitwait:
#!/bin/bash
#
# gitwait - watch file and git commit all changes as they happen
#
while true; do
inotifywait -qq -e CLOSE_WRITE ~/.calendar/calendar
cd ~/.calendar; git commit -a -m 'autocommit on change'
done
Run Code Online (Sandbox Code Playgroud)
这可以推广到等待文件和/或目录列表以及相应的inotifywait进程,并在文件更改时重新启动每个inotifywait.
Nev*_*nel 26
当我自己遇到这个问题时,之前的答案建议inotifywait为这项工作提示我正确的方向,所以我写了一个小脚本.首先,这只能递归地观察整个文件夹(与Lester Buck的例子相反),但后来我还想在其他地方看一个文件,所以我扩展了它.
结果是当前调用的脚本gitwatch,就像它所做的那样:它监视文件或文件夹以进行更改(使用inotifywait),并将它们提交到git存储库.
您可以在github上找到脚本,更多信息和说明:https://github.com/nevik/gitwatch
Red*_*arf 11
我想在Windows中执行此操作,并发现最好的方法是使用Directory Monitor检查更改,然后在检测到更改时运行:
程序:cmd.exe
参数:/ CC:\ pathToBatchFile.bat
该批处理文件包含:
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"
))
Run Code Online (Sandbox Code Playgroud)
我还尝试在那里添加另一个命令来添加文件("%PROGRAMFILES(X86)%\git\bin\sh.exe" --login -i -c "git add *.*"),但我认为我没有正常工作.
我还做了一个post-commit钩子包含:
#!/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
Run Code Online (Sandbox Code Playgroud)
(如果有任何冲突,那么它将中止拉动并中止推动,但没有任何明确的方式来判断发生了什么 - 最终我们因为这个缺陷而放弃了整个想法.)
那个curl命令告诉我的服务器它需要对代码进行拉动.在php中处理它所需要的只是:
<?
$r = $_GET['r'];
if (!empty($c)) {
//use system instead of exec if you want the output to go back to the git client
exec("cd /path/to/repo/parent/$r; sudo git reset --hard HEAD; sudo git pull;");
echo "\n\nServer: Updated\n\n";
} else {
echo "\n\nServer: UPDATE FAILED\n\n";
}
?>
Run Code Online (Sandbox Code Playgroud)
唯一的问题是它需要由root用户而不是apache用户运行,所以我还必须创建一个/etc/sudoers.d/包含以下内容的文件:
www-data ALL = NOPASSWD: /usr/bin/git
Run Code Online (Sandbox Code Playgroud)
对我来说,我认为这非常有效.目录监视器可以配置为在启动时运行并最小化,并且可以监视多个不同的文件夹
小智 8
#!/bin/bash
git commit -a -m "autoupdate `date +%F-%T`"
git push
Run Code Online (Sandbox Code Playgroud)
自动修复当前日期和时间.
我编写了一个程序GitPrime,为您当地的Git存储库提供自动保存.现在很容易在你破坏它之前回滚!Bitbucket存储库.
这应该适用于任何支持bash shell的平台,包括Windows + Cygwin.
小智 6
如果有人试图从Powershell做到这一点,我使用以下成功:
& "C:\Program Files (x86)\Git\bin\sh.exe" -c "cd D:\PATH\TO\REPO && git add --all && git commit -m 'Automatic Commit Message Goes Here' && git push origin master"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
73226 次 |
| 最近记录: |