简体   繁体   English

使用Git将目录推送到一个远程目录,而不是另一个目录

[英]Push a directory to one remote but not another with Git

I am using Git as part of my web development workflow. 我将Git用作Web开发工作流程的一部分。 I have a hook that creates a backup of the database before a commit. 我有一个挂钩,可以在提交之前创建数据库的备份。 I then push everything up to a master repo for backup purposes. 然后,我将所有内容推送到主存储库以进行备份。 Then when I'm ready I push everything to the live server. 然后,当我准备就绪时,将所有内容推送到实时服务器。 However I do not want the database backups to be pushed to the live server for security. 但是,我不希望将数据库备份推送到实时服务器中以确保安全。

Is there a way to tell Git to not copy the database backups when pushing to the live remote but still have it push the database backups to the master repo? 有没有一种方法可以告诉Git在推送到实时远程服务器时不复制数据库备份,但是仍然可以将数据库备份推送到主仓库?

I have a hook that creates a backup of the database before a commit. 我有一个挂钩,可以在提交之前创建数据库的备份。

Is this a local hook making local database backups? 这是进行本地数据库备份的本地挂钩吗?

Instead, you should make a database backup on a staging server in a post-update or pre-receive hook. 相反,您应该在更新后或预接收挂钩中在登台服务器上进行数据库备份。 This workflow might be suitable for one person, but you're going to have issues if someone else is committing sql dumps. 此工作流程可能适合一个人,但是如果其他人正在提交sql转储,您将遇到问题。

When you make the database dump in one of those hooks, don't put them in your git repo. 当您将数据库转储到其中的一个挂钩中时,请勿将其放入git存储库中。 Put them somewhere else on the file system. 将它们放在文件系统上的其他位置。 That way, your backups don't stay under version control. 这样,您的备份就不会受到版本控制。

A typical workflow will be: 典型的工作流程为:

  1. work locally and make some commits 在本地工作并做出一些承诺
  2. push your commits to remote 将提交推送到远程
  3. remote hook makes backup of database 远程挂钩使数据库备份

If you have two remotes, one for staging and one for production, all you have to do is push to staging to make your backups and push to production to deploy the live project. 如果您有两个远程控制器,一个用于暂存,一个用于生产,那么您要做的就是推向暂存进行备份,然后推向生产以部署实时项目。

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

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