git post-receive hook does not delete files

后端 未结 3 1620
生来不讨喜
生来不讨喜 2021-01-06 16:59

I\'m trying out git at the moment, and am trying to create a workflow so that a push to a bare remote repo on the server will update 2 different sites based on different bra

相关标签:
3条回答
  • 2021-01-06 17:30

    I ended up doing

    #!/bin/sh
    GIT_WORK_TREE=/www/development/ git checkout -f master
    GIT_WORK_TREE=/www/development/ git clean -fdx
    GIT_WORK_TREE=/www/production/ git checkout -f production
    GIT_WORK_TREE=/www/production/ git clean -fdx
    

    based off @Koraktor 's answer.

    0 讨论(0)
  • 2021-01-06 17:41

    I think that the work-tree checkout does not record any information about the repository in the working directory. So when updating an already checked-out version, Git will not be able to tell which diff it would have to apply and as such which files it needs to remove.

    Easiest solution would be to remove all files in the folders before checking them out..

    0 讨论(0)
  • 2021-01-06 17:46

    You should probably use git-reset and git-clean:

    #!/bin/sh
    GIT_WORK_TREE=/www/development/ git reset --hard master
    GIT_WORK_TREE=/www/development/ git clean -fdx
    GIT_WORK_TREE=/www/production/ git reset --hard production
    GIT_WORK_TREE=/www/production/ git clean -fdx
    
    0 讨论(0)
提交回复
热议问题