[英]How to automate git to automatically clone a repo on the server?
I have a repo in which I want to push changes. 我有一个我想推动变化的回购。 I want to sync two repositories: ./pages.git into ./pages.
我想同步两个存储库:./ pages.git到./pages。 My git setup on my development machine pushes into pages.git.
我的开发机器上的git设置会推送到pages.git。 But the web-application works with ./pages.
但是网络应用程序与./pages一起使用。
git clone pages.git pages
fatal: destination path 'pages' already exists and is not an empty directory.
Well now I delete the pages directory and git clone works. 那么我现在删除pages目录和git clone工作。 But that's not the clean solution, isn't it?
但那不是干净的解决方案,不是吗?
Is there any way to do that without having to delete the pages directory manually? 有没有办法做到这一点,而无需手动删除页面目录? I'd like to automate that process so that git automatically performs the actions whenever I push.
我想自动化该过程,以便git在我推送时自动执行操作。
Best, Marius 最好的,马吕斯
Why not just create a post-receive hook for the pages.git
repository that will do a git pull
from within the pages
repository to pull over the changes? 为什么不直接为
pages.git
存储库创建一个post-receive钩子 ,它将从pages
存储库中执行git pull
来pages.git
更改? git clone
is designed to be run only once per resulting clone (hence why it complains until you delete the previous clone), whereas git pull
is designed to be run repeatedly whenever you want to update a repo with changes from another. git clone
被设计为每个生成的克隆只运行一次(因此它会在你删除前一个克隆之前一直抱怨),而git pull
设计为每当你想要用另一个克隆更改来更新一个repo时重复运行。
I have a hook setup for something essentially the same as this with a particular repository, here's the gist of it: 我有一个钩子设置,用于与特定存储库基本相同的东西,这里是它的要点:
cd /var/repos/path_to_mirror || exit
unset GIT_DIR
git pull origin master
path_to_mirror
is the equivalent of pages
in your situation. path_to_mirror
等同于您的情况中的pages
。 pages.git/.git/hooks/post-receive
file. pages.git/.git/hooks/post-receive
文件中。 In my understanding you're working on local
copy, push to pages.git
and have a copy for webapp
? 根据我的理解,你正在制作
local
副本,推送到pages.git
并获得webapp
的副本?
If so, you can use post-receive hook on pages.git
that will call git pull
on pages
or make a simple copy to pages
. 如果是这样,你可以使用后收到挂机
pages.git
,将调用git pull
在pages
或进行简单的复制到pages
。
Post-receive
hook works on remote repo after push from local one. 从本地推送后,
Post-receive
hook在远程repo上工作。 It is executed after all refs have been updated due to push
. 在由于
push
而更新了所有引用之后执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.