
seen from Malaysia

seen from Malaysia
seen from United States
seen from China
seen from Germany

seen from China

seen from Australia
seen from United States
seen from United States
seen from Netherlands
seen from United Kingdom
seen from Germany
seen from China

seen from Japan
seen from United Kingdom
seen from Israel
seen from Malaysia
seen from United States
seen from United States
seen from China
Git: convert carriage return \r to new line \n with git hook?
Git: convert carriage return \r to new line \n with git hook?
A fellow coder uses a Windows computer that is putting carriage returns everywhere in our source.
Is there a way to write a git hook that converts all \r\n to \n?
Note I haven’t used git hooks before, so a little extra hand-holding might go a long way :)
Best Answer
The simplest thing is to set core.autocrlf to false on The Windows side. (that way Git won’t do any conversion and will keep the…
View On WordPress
Automatisches Deployment via Git Hook
Automatisches Deployment via Git Hook
Moin,
Ich möchte Euch heute mal grob erklären, wie man seine Webseite mithilfe eines Hooks für Git automatisch auf dem gleichen Server deployen kann. Auf meinem V-Server läuft Debian mit Gitolite, weshalb ich mich auf die Eigenschaften von dieser Distribution und diesem Hosting Tool beziehen werde. Vermutlich sind aber viele der angesprochenen Aktionen bei anderen Lösungen identisch bzw. müssen…
View On WordPress
Git-Fu, awk-won-do!
Recently, John posted this awesome piece of code that would syntax check your php files when committing your changes, using a git pre-commit hook.
git diff --cached --name-status | awk '{print $2}' | grep -e \.php$ | xargs -n1 php -l exit $?
However, I had a problem when we changed a directory name of where we kept a few php files. Because Git will see the rename as a 'delete' and an 'add'. So, git diff --cached --name-status will print both files. The syntax checker fails because it cannot open the deleted file!
I was trying workout a solution and when I failed, I went back to the master. He provided this solution to use 'awk' to filter out deleted files. So, the updated code is..
git diff --cached --name-status | awk '{ if ($1 != "D") print $2}' | grep -e \.php$ | xargs -n1 php -l exit $?
I didn't realise how powerful awk is. I have not used it, unless I copied and pasted a one-liner from someone else. I could not have got the solution from the ubuntu manual for sure. I need to pay more attention to simple but powerful tools like 'awk' and 'sed', lot more attention.
PS. Thanks John!
For the love of the git hook
In a test environment I had to disable the cron jobs before checking out updates. Because, I was using:
$ git checkout -f master
After the updates are pushed from the local repo. This is great but it would take out my changes that are configured for the test server but not meant to be committed. Had a solution for that too. I have the changes stashed before, so:
$ git stash apply
would apply the changes back and keep the stash. However, there was a split second, where the code would be production code and the cron job picking it up. I was disabling the cron by commenting lines and undoing that after each checkout.
This was painful: Until I came across this link. I didn't know you could pass a file as an argument to the command crontab. http://www.linuxquestions.org/questions/linux-newbie-8/disable-crontab-task-661142/#edit3239883
Now, I have exported my crontab to a file, and added the rest of the commands to a git hook. Post-receive hook to be exact.
# remove crontab crontab -r cd /path/to/working/dir/ unset GIT_DIR git checkout -f master git stash apply # apply crontab from file crontab /path/to/crons_file
All I have to do is push from local machine and the rest is taken care of.