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 :)
这看起来似乎是一个愚蠢的问题,但我觉得我对GIT理解得相当好,但我似乎无法按照自己的意愿设置我的开发环境。我要么缺少一些非常简单的东西,要么就是我错了:)
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.
我在我的服务器上初始化了一个裸git repo,将它克隆到我的本地机器,提交了我的文件并推送到原点。然后,在本地我创建了三个分支(主,发布,开发)并将它们全部发布到原点。我打算让多个开发人员从开发分支中撤出,我想确保他们不能推送到主分支,但对于另一个问题可能更好。
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.
现在,我在本地对文件进行了更改,然后将它们上传到测试服务器并通过Web浏览器检查测试服务器。我不得不想象这是大多数人测试他们的工作的方式,除非他们将他们的计算机配置为Web服务器并安装了php和mysql。一旦我对我的变化感到满意,我就把它们推到原始仓库,一切正常。
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.
我的挑战在于保持测试服务器与本地计算机同步。我已经尝试在我的远程测试目录中设置一个repo,并且我已经在我的本地git repo中添加了第二个远程,希望我可以推送到测试仓库,以便将测试服务器上的文件与我的本地文件同步。但我无法弄清楚如何使用两个遥控器并使它们与我的本地机器保持同步。
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.
如果我创建一个新的本地分支,检查它以开始处理新功能,然后将分支推送到我的测试远程,测试远程上的头仍然是主,而不是我的新功能分支。因此,我在本地更改功能分支,但是当我通过coda将更改发布到测试服务器时,我实际上是在更改测试仓库的主分支上的文件。如果我无法将我的测试快照与本地快照保持同步,我不知道如何充分利用gits分支功能。
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!
我在本地开发和测试真的非常重要吗?当您需要远程测试时,如何使用git建立开发环境?有一个测试回购完全错误的方式来考虑这个?必须有一种方法可以拥有多个遥控器,并将它们签出到推送的最新分支,这样您就可以在测试服务器上远程同步本地文件的实例。请帮忙!
1 个解决方案
#1
3
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.
最好在本地测试。你可以用这种方式更快地迭代。快速迭代非常重要。您花在git推送和远程连接延迟上的时间加起来,并且比建立一个完整的本地开发环境花费更多。
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.
无论哪种方式,在某些时候,您还需要远程测试您的更改。您可以使用测试服务器上的post-receive挂钩来实现。这是一种方法。
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
- 在测试仓库中创建一个post-receive挂钩,用于从新收到的分支更新网站
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.
把它放在.git /测试钩子中,并使其可执行。
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:
我通常在版本控制下将upgrade.sh脚本保存在我的项目中,并从hooks目录创建一个符号链接。 upgrade.sh升级脚本的主要工作是将部署目录重置为您推送的分支:
#!/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.
在大多数情况下,你想做更多的事情,例如在我的Django网站上,我需要重新生成静态内容并重新启动信号到Apache。
I hope this will help you get started.
我希望这会帮助你开始。
#1
3
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.
最好在本地测试。你可以用这种方式更快地迭代。快速迭代非常重要。您花在git推送和远程连接延迟上的时间加起来,并且比建立一个完整的本地开发环境花费更多。
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.
无论哪种方式,在某些时候,您还需要远程测试您的更改。您可以使用测试服务器上的post-receive挂钩来实现。这是一种方法。
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
- 在测试仓库中创建一个post-receive挂钩,用于从新收到的分支更新网站
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.
把它放在.git /测试钩子中,并使其可执行。
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:
我通常在版本控制下将upgrade.sh脚本保存在我的项目中,并从hooks目录创建一个符号链接。 upgrade.sh升级脚本的主要工作是将部署目录重置为您推送的分支:
#!/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.
在大多数情况下,你想做更多的事情,例如在我的Django网站上,我需要重新生成静态内容并重新启动信号到Apache。
I hope this will help you get started.
我希望这会帮助你开始。