git windows post pull

随声附和 提交于 2019-12-01 11:29:13

问题


I have recently converted from svn. My server is under Windows (don't blame me, it wasn't my choice :}

I have created a repo with two branches "master" and "stable".

On my server I want to get files from stable branch.

I have done:

git clone git://url/.git src
cd src
git checkout --track -b stable origin/stable

Previously I had a .bat script

cd my_repo_dir
svn update
echo APPLICATION_STAGE = 'production' > conf\__init__.py
net stop apache2.2
net start apache2.2

and it worked, now with git

cd my_repo_dir
git pull
echo APPLICATION_STAGE = 'production' > conf\__init__.py
net stop apache2.2
net start apache2.2

nothing is executing after git pull, whether it is successful, or up-to-date. It just exits to prompt with no warning.

I thought about hooks. I have created:

.git/hooks/post-receive
.git/hooks/post-update

both files with the same contents:

echo APPLICATION_STAGE = 'production' > conf\__init__.py
net stop apache2.2
net start apache2.2

and nope, it is not executing either... Maybe I am missing interpreted declaration line (#!/bin/sh on *nix) but I am not sure what it is on windows...


回答1:


Few points:

  • Make sure you have git.exe on path. Do a where git and you must get something like

    C:\Program Files (x86)\Git\bin\git.exe
    

    If git.cmd is being used ( from C:\Program Files (x86)\Git\cmd\git.cmd ), you have to do call git pull for it to continue execution. I would say add git.exe to path and start using it.

  • Even on Windows, you must have the shebang - #!/bin/sh for the hooks to properly run.

  • If you want a hook to run on pull, you probably want to use the post-merge hook. post-receive and post-update run on remote repos when you push to them.




回答2:


git is probably a batch wrapper around the real executable. Use call git pull.

And those hooks only fire when content is pushed from a remote location, as far as I can tell from the documentation. So they're ignored for pull.



来源:https://stackoverflow.com/questions/6286982/git-windows-post-pull

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