简体   繁体   English

如何使用Git存储库进行Web开发(和部署)?

[英]How can I use Git repositories for web development (and deployment)?

Coming from a simple "edit directly on ftp" workflow, I want to try source version controlling. 来自简单的“直接在ftp上编辑”工作流,我想尝试源版本控制。 As I can imagine, GIT is a very popular choice. 我可以想象,GIT是一个非常受欢迎的选择。

I'm a single developer. 我是一名开发人员。 I have multiple websites I work on (each one in /home/domains/) on the remote server (Linux) and I wish to start working on them locally (Mac OS) and then pushing them back (updating the remote files). 我在远程服务器(Linux)上有多个我工作的网站(每个在/ home / domains /中),我希望在本地(Mac OS)开始处理它们,然后推回它们(更新远程文件)。

I didn't however understand how git is supposed to work for me. 然而,我没有理解git应该如何为我工作。 It looks like I have to have a "bare" repository, which I can't have because my projects already have files and folders, so that means I'd have to create a new bare repository and then push stuff locally and afterwards pull remotely. 看起来我必须有一个“裸”存储库,我不能拥有它,因为我的项目已经有文件和文件夹,所以这意味着我必须创建一个新的裸存储库,然后在本地推送东西,然后远程拉取。

This seems a bit weird, having 3 repositories (1 local and 2 remotes) when I only would work on 2 folders. 这看起来有点奇怪,当我只处理2个文件夹时,有3个存储库(1个本地和2个遥控器)。

Can I get some advice? 我能得到一些建议吗?

There are two standard, sane, options if you have online access between your server and your local system. 如果您在服务器和本地系统之间进行在线访问,则有两种标准的,理智的选项。

First, you can add a remote for the other repository and pull all committed changes from the other repository before you start making changes. 首先,您可以为其他存储库添加远程数据库,并在开始进行更改之前从其他存储库中提取所有已提交的更改。 This means, for example, if you make a change on the local system, you will have to ssh over to the server and pull to get the changes over there. 这意味着,例如,如果您在本地系统上进行更改,则必须ssh到服务器并拉动以获取更改。

Second, you can create a bare repository to act as the master. 其次,您可以创建一个裸存储库来充当主服务器。 This is the standard model for shared repositories, especially when there are multiple users involved but it works when one user is involved and is preferred when there might not be full-time bidirectional access between the two systems. 这是共享存储库的标准模型,尤其是当涉及多个用户但是当涉及一个用户时它可以工作,并且当两个系统之间可能没有全时双向访问时是首选。 This bare repository could be on the mac system, on the linux server, or on a third system (such as github, for example). 这个裸存储库可以在mac系统上,在linux服务器上,或在第三个系统上(例如github)。 The workflow in this case would be to pull all changes from the bare repository, make a change, commit, and then push that change to the bare repository. 在这种情况下,工作流程将从裸存储库中提取所有更改,进行更改,提交,然后将该更改推送到裸存储库。 Absent special hooks, you still would need to ssh over to the server and issue a pull to update the live website. 如果没有特殊的钩子,你仍然需要ssh到服务器并发出拉动以更新实时网站。

You could create the new repository by doing a git clone --mirror --bare from the server repository. 您可以通过从服务器存储库执行git clone --mirror --bare来创建新存储库。 Afterwards you would git add remote origin URL-TO-NEW-BARE-REPOSITORY on the server. 之后你会在服务器上git add remote origin URL-TO-NEW-BARE-REPOSITORY You could either do the same on the macosx system or git clone URL-TO-NEW-BARE-REPOSITORY 您可以在macosx系统或git clone URL-TO-NEW-BARE-REPOSITORY

It is technically possibly to configure the system to allow the macosx system to push to the checked out linux working directory. 从技术上讲,可能需要配置系统以允许macosx系统推送到已检出的linux工作目录。 I do not recommend this, especially if you might be making changes on that repository as well, since the process might/would destroy any uncommitted change. 我不建议这样做,特别是如果您可能正在对该存储库进行更改,因为该进程可能/将会破坏任何未提交的更改。 A similar problem could happen with automatic hooks which would automatically send/checkout incoming commits to the live webserver directory. 自动钩子可能会发生类似的问题,它会自动发送/检出传入的提交到实时webserver目录。

For reference purposes, consider http://toroid.org/ams/git-website-howto and http://joemaller.com/990/a-web-focused-git-workflow/ 出于参考目的,请考虑http://toroid.org/ams/git-website-howtohttp://joemaller.com/990/a-web-focused-git-workflow/

My workflow is like this: 我的工作流程是这样的:

  • I have a remote repo and a local one (they are normal repos, not bare ones) 我有一个远程回购和一个本地回购(他们是正常的回购,而不是裸露的回购)
  • I work on my local repo 我在当地的回购工作
  • I commit 我承诺
  • I push my changes to remote repo 我将我的更改推送到远程仓库
  • I ssh to the remote machine and run git reset --hard on remote repo to update the files 我ssh到远程机器并在远程git reset --hard上运行git reset --hard来更新文件

Works pretty well for me, especially because I use Fabric to do the push and reset steps, so it comes down to single fab push . 对我来说非常好用,特别是因为我使用Fabric来执行推送和重置步骤,所以它归结为单个fab push

To clarify I'm a single developer, might not work so well if you develop your webpage in a larger team. 为了澄清我是一个单一的开发人员,如果你在一个更大的团队中开发你的网页,可能效果不好。

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

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