如何在远程测试时设置git开发环境 [英] How to set up a git development environment when you're testing remotely
问题描述
现在,我在本地对文件进行更改,然后将其上传到测试服务器,并通过Web浏览器检查测试服务器。我不得不想象这是大多数人如何测试他们的工作,除非他们的计算机配置为Web服务器并安装了PHP和MySQL。一旦我对自己的修改感到满意,我会将它们推送到原始库,并且一切正常。
我的挑战在于让测试服务器与我的本地保持同步机。我已经尝试在远程测试目录中设置一个回购站,并且我已经为本地git回购站添加了第二个远程站点,希望能够推送到测试回购站以使测试服务器上的文件与本地文件同步。但我不知道如何有两个遥控器,并保持他们与我的本地机器同步。
如果我创建一个新的本地分支,请检查它以开始处理新功能,然后将分支推送到测试远程,测试远程的头部是仍然掌握,而不是我的新功能分支。因此,我在本地对功能分支进行了更改,但是当我通过结尾将更改发布到测试服务器时,实际上我正在更改测试回购的主分支上的文件。如果我无法保持测试快照与本地快照同步,我不知道如何充分利用gits分支功能。
我在本地开发和测试真的非常重要吗?当你必须远程测试时,如何使用git建立开发环境?有一个测试回购完全错误的方式来思考这个问题?必须有一种方法可以拥有多个遥控器,并让他们结帐到最新推送的分支,这样您就可以在测试服务器上远程同步本地文件的实例。请帮助!
最好在本地进行测试。你可以用这种方式更快地迭代。快速迭代是非常重要的。你花费在git推送和远程连接延迟上的时间加起来,并且花费的不仅仅是设置一个完整的本地开发环境。
无论哪种方式,另外您还需要远程测试您的更改。您可以使用测试服务器上的post-receive挂钩来完成此操作。 在测试服务器上:
- 创建您的回购的一个光秃的克隆。我们称这个回购为测试。
- 从测试中克隆,并将其设置为您在浏览器中测试的远程网站
- 创建帖子 - 在测试回购中接收钩子,将从新收到的分店更新网站
后接收钩脚本:
#!/ bin / sh
while read oldrev newrev refname
do
upgrade_sh =。/ upgrade。 sh
如果测试-e $ upgrade_sh;然后
upgrade_sh = $(readlink $ upgrade_sh || echo $ upgrade_sh)
echo调用升级脚本:$ upgrade_sh
$ upgrade_sh $ refname
else
echo不调用非 - 存在的升级脚本:$ upgrade_sh
fi
完成
code> .git / hooks 进行测试,并使其成为可执行文件。
我通常保留升级.sh
脚本在版本控制下的项目中,并从钩子
目录创建一个符号链接。升级脚本的 upgrade.sh
主要工作是将部署目录重置为您推送的分支:
#!/ bin / sh -e
unset GIT_DIR
git checkout -f $ 1
在大多数情况下,您希望做的比这更多,例如在我的Django网站上,我需要重新生成静态内容并向Apache重新启动信号。
我希望这会帮助您开始。
This may seem like a silly question, but I feel like I understand GIT fairly well, and yet I can't seem to set up my development environment as I would like. I'm either missing something really simple, or I'm going about it all wrong :)
I initialized a bare git repo on my server, cloned it to my local machine, committed my files and pushed to origin. Then, locally I created three branches (master, release, develop) and published them all to origin. I intend to have multiple developers pulling from the develop branch, and I would like to make sure they can't push to the master branch but that may be better for a different question.
Now, I make my changes to the files locally, and then upload them to the testing server and check the testing server through the web browser. I would have to imagine that this is how most people test their work unless they have their computers configured as web servers and have php and mysql installed. Once I'm happy with my changes, I push them to the origin repo, and everything works fine.
My challenge comes in keeping the testing server in synch with my local machine. I've tried setting up a repo in my remote testing directory, and I've added a second remote to my local git repo, hoping I could push to the testing repo to synch the files on the testing server with my local files. But I can't figure out how to have two remotes and keep both of them in synch with my local machine.
If I create a new local branch, check it out to start working on a new feature and then push the branch to my testing remote, the head on the testing remote is still master and not my new feature branch. Therefore, i'm making changes locally to a feature branch, but when I publish the changes to the testing server through coda, I'm actually changing files on the master branch of the testing repo. If I can't keep my testing snapshots in synch with my local snapshots, I don't know how to take full advantage of gits branching features.
Is it really that crucial that I am developing AND testing locally? How on earth does one set up a development environment with git when you have to test remotely? Is having a testing repo the completely wrong way to think about this? There must be a way to have multiple remotes and have them checkout to the latest branch that is pushed so you can have an instance of your local files in synch remotely on a testing server. PLEASE HELP!
It's best to test locally. You can iterate faster that way. Fast iteration is extremely important. The time you spend on git pushes and remote connection latency add up, and will cost you more than setting up a complete local dev env.
Either way, at some point or another you will need to test your changes remotely as well. You can do that with a post-receive hook on your test server. Here's one way to do it.
On the test server:
- Create a bare clone of your repo. Let's call this repo "testing".
- Clone from testing, and set it up as the remote website you test in your browser
- Create a post-receive hook in the testing repo that will update the website from the newly received branch
The post receive hook script:
#!/bin/sh
while read oldrev newrev refname
do
upgrade_sh=./upgrade.sh
if test -e $upgrade_sh; then
upgrade_sh=$(readlink $upgrade_sh || echo $upgrade_sh)
echo calling upgrade script: $upgrade_sh
$upgrade_sh $refname
else
echo NOT calling non-existent upgrade script: $upgrade_sh
fi
done
Put it in .git/hooks
of testing, and make it executable.
I usually keep the upgrade.sh
script inside my project under version control, and create a symlink to it from the hooks
directory. The upgrade.sh
main job of the upgrade script is to reset the deployment directory to the branch that you pushed:
#!/bin/sh -e
unset GIT_DIR
git checkout -f $1
In most cases you want to do more than this, for example on my Django websites I need to regenerate static content and signal restart to Apache.
I hope this will help you get started.
这篇关于如何在远程测试时设置git开发环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!