자식 자동 커밋 만들기
git을 사용하여 모든 변경 사항을 파일에 기록하고 싶습니다.
파일을 업데이트 할 때마다 git 'commit'을 자동으로 설정하는 방법이 있습니까? 따라서 파일을 변경할 때마다 새로운 커밋이 있습니까?
이상적으로는 사용자가 자식이이면에서 실행되고 있음을 알지 못하도록하고 싶습니다. 그런 다음 사용자는 파일에 대한 변경 사항을 "실행 취소"할 수 있으며 이는 이전 버전을 git에서 가져 와서 달성 할 수 있습니다.
Linux 에서는 파일 내용이 변경 될 때마다 inotifywait 를 사용 하여 자동으로 명령을 실행할 수 있습니다 .
편집 : 다음 명령은 file.txt가 저장 되 자마자 커밋합니다.
inotifywait -q -m -e CLOSE_WRITE --format="git commit -m 'autocommit on change' %w" file.txt | sh
이전의 inotifywait 답변은 훌륭하지만 완벽한 솔루션은 아닙니다. 작성된 것처럼 파일에서 한 번만 변경하면 한 번만 커밋됩니다. 파일을 편집하면 원래 이름으로 새 inode가 생성되는 일반적인 경우에는 작동하지 않습니다. inotifywait -m 은 이름이 아닌 inode에 의해 파일을 따르는 것 같습니다. 또한 파일이 변경된 후에는 git add 또는 git commit -a 없이 git commit 을 위해 준비되지 않습니다 . 일부 조정을 수행하면 데비안에서 캘린더 파일의 모든 변경 사항을 추적하는 데 사용합니다.
/etc/rc.local :
su -c /home/<username>/bin/gitwait -l <username>
/ 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
이는 파일 및 / 또는 디렉토리 목록 및 해당 inotifywait 프로세스 를 대기 하고 파일이 변경 될 때 각 inotifywait 를 다시 시작 하도록 일반화 될 수 있습니다 .
이 작업에 대해 inotifywait 를 권장하는 이전 답변 은이 문제가 발생했을 때 올바른 방향으로 나를 기울여서 약간의 스크립트를 작성했습니다. 먼저 전체 폴더를 재귀 적으로 볼 수 있었지만 (Lester Buck의 예와 반대) 다른 곳에서 파일을보고 싶었으므로 확장했습니다.
결과는 현재라는 스크립트gitwatch
입니다. 즉, inotifywait를 사용하여 파일이나 폴더에서 변경 사항을 감시하고 git 저장소에 커밋합니다.
github에서 스크립트, 자세한 정보 및 지침을 찾을 수 있습니다 : https://github.com/nevik/gitwatch
git-wip 은 저에게 잘 맞는 훌륭한 솔루션입니다. "WIP"는 "작업 진행 중"을 나타냅니다. 'git wip'을 실행할 때마다 변경 사항이 별도의 분기로 커밋됩니다. 명령 행에서 실행할 수 있지만 파일을 작성할 때마다 git-wip을 자동으로 실행하는 vim 및 emacs의 확장자가 있습니다.
Windows 에서이 작업을 수행하고 싶었고 디렉토리 모니터 를 사용 하여 변경 사항을 확인한 다음 변경 사항이 감지되면 변경 사항을 감지하는 것이 가장 좋은 방법이라는 것을 알았습니다 .
프로그램 : 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"
))
또한 파일 ( "%PROGRAMFILES(X86)%\git\bin\sh.exe" --login -i -c "git add *.*"
) 을 추가하기 위해 다른 명령을 시도했지만 제대로 작동하지 않는다고 생각합니다.
또한 다음을 포함하는 커밋 후 후크를 만들었습니다.
#!/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
(충돌이 있으면 풀을 중단하고 푸시를 중단하지만, 그 일이 일어 났음을 알 수있는 명확한 방법은 없었습니다. 결국 우리는이 하나의 결함으로 인해 전체 아이디어를 포기했습니다.)
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";
}
?>
그것의 유일한 문제는 아파치 사용자 대신 루트 사용자가 실행해야했기 때문에 /etc/sudoers.d/
다음 을 포함 하는 파일을 만들어야했습니다 .
www-data ALL = NOPASSWD: /usr/bin/git
나를 위해, 나는 그것이 꽤 견실하게 작동했다고 생각합니다. 시작시 실행되도록 최소화하고 시작하도록 디렉토리 모니터를 구성 할 수 있으며 여러 다른 폴더를 볼 수 있습니다
#!/bin/bash
git commit -a -m "autoupdate `date +%F-%T`"
git push
autopushing with current date and time.
Inotify really sounds like the right tool for the job.
There is a tool called incron which could be exactly what you are looking for. You can specify files or folders (and event types, like "change", "create", "unlink") in something like a crontab, and a command to run when such an event occurs.
In contrast to inotifywait (which would be the analog of the poor man's cron sleep 10;do stuff
), this will catch every event, not just the first.
I haven't used it myself, but from the documentation it doesn't look too complex to setup.
I wrote a program, GitPrime, to provide autosave for your local Git repositories. Now easy to roll back to before you busted it! Bitbucket repository.
This should work on any platform that supports a bash shell including Windows+Cygwin.
In case anyone tries to do this from Powershell I had success using the following:
& "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"
Two solutions that I like are etckeeper -- which can be adapted to a custom directory other than /etc
:
mkdir /foo
etckeeper -d /foo init`
etckeeper -d /foo commit 'message'
And gitwatch -- specially the instructions of how to use it with supervisord
.
If you know the name of the file and you want to monitor only one (or a few files), you can simply call "git commit" every few minutes to achieve this. If the file hasn't changed, git will just complain and you'll have to ignore this error but other than that, there will be no corruption.
In addition to that, you'll want to mark these files as "auto commit" in order to be able to commit manually as well. This way, the user can see the automatic changes and also the bigger "logical" changes which are accompanied by commit comments to explain that has changed since the last manual commit.
For example, use "AUTOCOMMIT" as the commit message. Later, you can write a tool to purge these commits using git log (to find out the revisions to kill) or you can try to create a branch AUTOCOMMIT using a brute force collision resolve strategy to hammer in the "manual commits".
Another option is to use the git low-level commands to build your own specialized repository.
Lastly, you could copy the file to a new name ("$filename.ac") while doing auto commits to distinguish between the manual and automatic versions.
I'm pretty sure you'd need to hook that into whatever editor your users are using. You could write something to poll for changes, but depending on usage patterns, the polling frequency might need to be incredibly high to make sure it was picking up individual changes instead of multiple changes.
It sounds like you're looking for something similar to etckeeper, which is designed to automatically check all your changest to /etc/* into git (or whatever VCS you want), but I see no reason it couldn't be used with files other than those in /etc.
If you only want to deal with one single file, maybe that wouldn't be perfect, but if you want to keep track of everything in a given directory, I think it's worth checking into.
This script doesn't run when a user changes the file, but it could be run as a cron job (by dropping it into an /etc/cron.* directory), which is also a reasonable solution.
This script will iterate through your /srv/www directory (change it to wherever all of your sites are stored), add, commit, and push all files, and log everything to /var/log/gitlog.txt
now=$(date +"%m.%d.%Y_%T")
logfile='/var/log/gitlog.txt'
for dir in /srv/www/*/
do
echo -e '\n' >> $logfile
echo "autocommit $dir $now" >> $logfile
echo "--------------------------" >> $logfile
cd $dir
git add . >> $logfile
git commit -am "autocommit $now" >> $logfile
git push origin master >> $logfile
done
i had the same problem and on mac launchd provides you with a great solution. it will watch a file or a directory and if there are changes you can run an app or anything else...
I made this tiny shell script to monitor files status and trigger commands such as git commit on build success.
Feel free to download and try it.
https://github.com/nzvincent/nzvincent-github/blob/master/inotify-tools/inotify.sh
If you don't want to mess up with codes and and linux commands then I would like to suggest you using Dropbox for coding. I found Dropbox is great for coding. I just install dropbox on my pc and created a virtual host. Virtual Host is pointing to my dropbox folder. Whenever I make the changes on any file and press CTRL+S (i.e save) it creates a new version of file. I just love the technology, here is the profit of using dropbox for coding.
- Time Saving :- No more Push and Pull for teammates. You can save your time, if you irritate pushing and pulling the codes again and again.
- 개발자 그룹과 함께 작업하는 경우 모든 개발자 PC에 dropbox를 설치 한 다음 동일한 폴더에서 작업하면 충돌이 있으면 충돌 파일을 자동으로 생성합니다.
- 실수로 파일을 삭제 한 경우 클라우드 휴지통에서 파일을 복구 할 수 있습니다
- 저장할 때마다 버전 관리.
마침내 저는 Dropbox 프로모터가 아닙니다.
참고 URL : https://stackoverflow.com/questions/420143/making-git-auto-commit
'development' 카테고리의 다른 글
비트 시프트는 엔디안에 의존합니까? (0) | 2020.06.18 |
---|---|
여러 열에서 고유 한 sqlalchemy (0) | 2020.06.18 |
왜 슈퍼 클래스 __init__ 메소드가 자동으로 호출되지 않습니까? (0) | 2020.06.18 |
왜 'rm'대신 'git rm'을 사용하여 파일을 제거합니까? (0) | 2020.06.18 |
Python 2와 3 사이의 numpy 배열의 피클 비 호환성 (0) | 2020.06.18 |