1

I would like some advice about how to setup Git for an existing live website on a production server (only hosting one site - no vHosts etc).

There are several examples of how to achieve this - but all refer to when you are starting a new project.

I'd like to replicate this scenario which describes how to setup a remote repository and create a post-update hook to copy files into the www directory upon checkout. This is the concept I can grasp (https://danielmiessler.com/study/git/#website)

However, I'm facing the scenario where there is live code on a webserver, I want to initialise Git on all the existing live files, and then develop on my local machine.

I'm sorry that I don't know enough about Git understand how to achieve the result described in Daniel's article from my starting position of having live code on a server in production.

My Config (CentOS 6/Nginx):

Git Repository (this should be in a separate location from www)

/home/username/repository/website.git

Post Update Hook File Location

/home/username/repository/website.git/hooks/post-update

Post Update Hook File Entry

GIT_WORK_TREE=/var/www/website git checkout -f

Website Directory

/var/www/website

I also have a ignore file

/var/www/website/.gitignore

Could someone kindly assist with Git commands. I can initialise /var/www/website/.git (with an initial commit) but don't know how to then setup /user/username/repository/website.git to work in the way described in the article.

4

1 回答 1

1

指南中显示的步骤对于新项目或现有项目完全相同。它在创建 html 文件的步骤 2 中提供的示例可以通过将现有内容添加到您的工作目录来替换。

因此,git init请在您的新工作文件夹中运行,尽管这可以在现有文件夹中完成,因为它不会更改任何当前文件。将您当前的 Web 内容放入同一个文件夹中,无论是从备份中导入还是从您的实时环境中直接下拉,这并不重要。

现在您需要git add为所有想要在版本控制下的文件运行命令。您不需要单独执行它们,接受通配符和目录。用于git status检查您想要的所有内容是否已上演,然后git commit -m带有一些合适的消息。

我建议您在本地创建另一个目录并在git init --bare那里发出命令,设置挂钩以推送到另一个目录,然后推送到裸仓库

git push --set-upstream  [/your/local/bare/repo] master

只是为了检查您是否拥有所有内容并且您对 git 感到满意

于 2015-04-15T10:56:23.763 回答