Simple git post-commit hook to copy committed files to a certain folder

前端 未结 1 582
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 05:12

I would like to automatically copy the committed files to a certain folder so they can be viewed in a browser, but I would like to do this without having to create a bare re

1条回答
  •  情深已故
    2020-12-05 05:46

    A good way of doing this is to create a post-commit that runs git checkout -f with the work tree set to the directory that is exposed by your web server and the git directory set to the .git directory in your development repository. For example, you could create a .git/hooks/post-commit file that did:

    #!/bin/sh
    unset GIT_INDEX_FILE
    export GIT_WORK_TREE=/example.com/
    export GIT_DIR=/home/whoever/development/web-project/.git/
    git checkout -f
    

    Be careful with this, however - the -f means that git may remove or overwrite files to make /example.com/ match the tree in your most recent commit.

    (Remember to make the .git/hooks/post-commit file executable as well.)

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