我可以使用git让远程服务器保持最新状态吗? [英] Can I use git to keep a remote server up to date?
问题描述
我使用git来跟踪一个项目,如果可能的话,我想设置一些东西,以便git处理我所有的代码分段,我可以有一个本地存储库用于测试,然后将更改推送到服务器用git让他们活下去。然而,在尝试使用标准的 git push
调用时,我最终会遇到不一致的分支以及可怕的历史冲突。有没有办法使用git来管理登台?
I'm using git to track a project, and if it's possible, I'd like to set things up so git handles all my code staging, I can have a local repository for testing, and then push changes to the server with git to make them live. However, in trying to use standard git push
calls, I just end up with inconsistent branching and a terrible mess of conflicting histories. Is there a way to manage staging using git?
推荐答案
You have in this blog post an example of Git repo used for staging:
IDE => local Git repository => remote bare Git repository
=> Git repository with the live web application
它涉及裸回购方面的更新后钩子,为了触发活动Web服务器端的回购更新。
It involves a post-update hook on the bare repo side, in order to trigger the update of the repo on the live web server side.
最后一步是定义更新后钩子裸仓库接收数据时调用该脚本。
要启用后更新钩子,我们必须使hooks / post-update
可执行文件或重命名hooks / post-update.sample
至hooks / post-update
在这个脚本中,我们只需切换到实时应用程序的文件夹,然后启动pull操作:
The final step is to define the "post-update" hook script on the bare repository, which is called when the bare repository receives data.
To enable the "post-update" hook, we have to either makehooks/post-update
executable or renamehooks/post-update.sample
tohooks/post-update
, depending on the Git version.
In this script, we simply change to the folder of the live application, and start the pull operation:
#!/bin/sh
cd $HOME/example.org
unset GIT_DIR
git pull bare master
exec git-update-server-info
有一个裸露的远程回购是因为它不鼓励用工作目录进行回购。
The reason there is a bare remote repo is because it is "discouraged" to do a push into a repo with a working directory.
这篇关于我可以使用git让远程服务器保持最新状态吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!