Git post-receive hook. Move everything except a few folders

随声附和 提交于 2020-01-03 01:47:27

问题


I have implemented a post-receive hook on my server (git was initialized with git init --bare). Hook was created in the following way:

cd repo/hooks/
touch post-receive
chmod 777 post-receive

Then inside of the file I have:

#!/bin/sh
GIT_WORK_TREE=/var/www
export GIT_WORK_TREE
git checkout -f

Right now when I push my local changes everything gets moved to /var/www folder. The problem is that I do not want some of the folders to be moved. For example I have folder1, and folder2 there which I do not want to be moved. Currently I am manually removing these folders after the push, but this is a ridiculous work and I would like to automate it.

I am on ubuntu 14.04 / git 2.1


回答1:


I am manually removing these folders after the push

You could just ad this step in your hook

The other way is to try and set up a sparse checkout (since you can exclude folders in the sparse-checkout file).

echo "/*" > .git/info/sparse-checkout
echo "!folder1/" >> .git/info/sparse-checkout
echo "!folder2/" >> .git/info/sparse-checkout


来源:https://stackoverflow.com/questions/25699245/git-post-receive-hook-move-everything-except-a-few-folders

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!