简体   繁体   English

Git:推送后删除文件

[英]Git: Remove files after push

I have a local repository at my workstation and remote repository on server (phpfog.com). 我的工作站有一个本地存储库,服务器上有远程存储库(phpfog.com)。 My application generates cache files and I want to delete them (on the remote) everytime someone pushes: is it possible and if so - how? 我的应用程序生成缓存文件,我想在每次有人推送时删除它们(在遥控器上):是否可能,如果可能 - 如何? FYI: These files are ignored using .gitignore (maybe there might be a way how to use this). 仅供参考:使用.gitignore忽略这些文件(可能有一种方法可以使用它)。

I've heard of git hooks but have little idea how to use them. 我听说过git hooks,但不知道如何使用它们。

Thank you 谢谢

Edit: I want to do git clean (remove untracked files) but on the remote and with every push. 编辑:我想做git clean(删除未跟踪的文件)但是在远程和每次推送。 These files are generated by application and this cannot be solved by .gitignore-ing them (in fact they are gitignored). 这些文件是由应用程序生成的,这不能通过.gitignore-ing来解决(事实上它们是gitignored)。

I think post-receive hook is what you are looking for. 我认为post-receive hook是你正在寻找的。

Just add a bash script to remote server which clean all cache file and specify it as post-receive hook. 只需将一个bash脚本添加到远程服务器,清理所有缓存文件并将其指定为post-receive hook。 For more information look at http://book.git-scm.com/5_git_hooks.html 有关更多信息,请访问http://book.git-scm.com/5_git_hooks.html

Why are people pushing files that are better ignored? 为什么人们推送更好被忽略的文件? Just git rm --cached them and commit and push. 只需git rm --cached它们并提交并推送。 Make sure they are properly added to the .gitignore and it would make sure people are not accidentally adding these files again and pushing them. 确保它们已正确添加到.gitignore ,这样可确保人们不会意外地再次添加这些文件并推送它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM