简体   繁体   English

带有git和github的工作流程以及实时网站和开发网站

[英]workflow with git and github with live website and development website

I have a live website that I want to use git/github. 我有一个实时网站,我想使用git / github。 The website has a local.config with database config and passwords, lots of user dirs, a cache dir and a database and I want to know how to best use git/gihub. 该网站有一个local.config,其中包含数据库配置和密码,大量用户目录,缓存目录和数据库,我想知道如何最好地使用git / gihub。 The first step is to move my live website into github. 第一步是将我的实时网站移至github。 Once I have moved it to github, I plan to clone it on a development server. 将其移至github后,我计划将其克隆到开发服务器上。 From the development server push updates to github and then ultimately to my live website. 从开发服务器将更新推送到github,最后到我的实时网站。

How can I commit all files to github without including the passwords in local.config? 如何在不将密码包含在local.config中的情况下将所有文件提交到github? Also, how can I keep local.config files on the live web-server, gihub and a development server without overwriting them when I commit a change from a development server? 另外,当我从开发服务器提交更改时,如何将local.config文件保留在实时Web服务器,gihub和开发服务器上而不会覆盖它们?

For the user dirs, I want to ignore all the individual user dirs AND the contents, however, I want to keep the main dir webroot/userdir (user dirs would go under webroot/userdir. For my cache dir, I want to ensure no cache is githubbed but I want the dir 'cache' to remain. 对于用户目录,我想忽略所有单个用户目录及其内容,但是,我想保留主目录webroot / userdir(用户目录将位于webroot / userdir下。对于我的缓存目录,我想确保没有缓存是githubbed,但我希望保留目录dir。

I am so worried also about deleting the live website or portions of it when I update it from github. 当我从github更新它时,我也担心删除实时网站或其部分。

Add your local.config file to gitignore before committing it. 提交之前,将local.config文件添加到gitignore中。 But have a copy of it wherever you want. 但是,无论您想去哪里,都可以得到它的副本。 Git will not touch the files that you choose to ignore. Git不会触摸您选择忽略的文件。

In short whatever you don't want to be githubbed is to be added to gitignore/exclude. 简而言之,您不想被githubbed的所有内容都将添加到gitignore / exclude中。 But this will mean that you are not version controlling those files. 但这将意味着您没有版本控制那些文件。

Hope this answers the question! 希望这能回答问题!

Happy gitting! 快乐的混蛋!

Mudassir Razvi is correct that you can use gitignore to stop tracking your local.config file. Mudassir Razvi是正确的,您可以使用gitignore停止跟踪您的local.config文件。 However, I typically find this to be bad practice (especially if you are creating an application for others to use such as with an open source project). 但是,我通常认为这不是一个好习惯(特别是如果您要创建供他人使用的应用程序(例如,与开源项目一起使用))。 I prefer to continue tracking changes to the local.config file so that you may still add new config variables moving forward. 我更喜欢继续跟踪对local.config文件的更改,以便您仍可以继续添加新的配置变量。 Once the website is cloned on the webserver, you can simply stop tracking changes to your config file on the live server. 将网站克隆到网络服务器上后,您只需停止在实时服务器上跟踪对配置文件的更改即可。

git update-index --assume-unchanged "config.local"

This has the same effect as adding it to the gitignore file, with the exception that it can add a little security by helping to hide your sensitive file. 这与将其添加到gitignore文件具有相同的效果,不同之处在于它可以通过帮助隐藏敏感文件来增加一点安全性。 This is particularly useful if your gitignore file is web accessible. 如果您的gitignore文件可通过网络访问,则这特别有用。

More importantly though, this prevents accidental updates if you mistakenly change or remove your gitignore file and it also allows your other clones to continue tracking changes since gitignore files are cloned as well. 不过,更重要的是,如果您错误地更改或删除了gitignore文件,这可以防止意外更新,并且由于也克隆了gitignore文件,它还允许您的其他克隆继续跟踪更改。

You can resume tracking any time with this command: 您可以随时使用以下命令恢复跟踪:

git update-index --no-assume-unchanged "config.local"

Also helpful, you can list which files are assume-unchanged at any time. 同样有用的是,您可以随时列出假定未更改的文件。

git ls-files -v|grep '^h'

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

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