在排除一些已提交文件的同时推送到远程服务器? [英] Push to remote server while excluding some committed files?
问题描述
我最近将Git集成到我的工作流程中,其功能给我留下了深刻的印象.通过ssh推送时,它不仅是一个很棒的VCS,而且还在FTP周围运行.不过,今天晚上我确实遇到了麻烦,我想知道你们中的好伙伴是否可以帮助我解决这个问题.
I recently integrated Git into my workflow, and I'm impressed with its capabilities. Not only is it a great VCS, it's running laps around FTP when pushing via ssh. I did run into a hitch this evening though, and I'm wondering if you fine folk can help me resolve it.
我要跟踪项目中的某些文件,但不想将其投入生产.有什么方法可以推送到生产服务器,同时从存储库中排除某些文件?两个很好的例子:
There are certain files in a project that I want to track, but don't want to push to production. Is there a way to push to a production server while excluding certain files from the repo? Two great examples:
- .less文件根本不需要放在生产服务器上,但绝对应该仍然跟踪
- 由于我的本地和生产环境在不同的域中运行,因此.htaccess文件略有不同.我仍然想跟踪这些规则,因为大多数规则都是通用的(如果丢失则很难重写)-但是每次我实时推送本地.htaccess时,都会破坏我的生产环境,因此我必须手动修复该文件.
如果可能的话,我想将所有内容保持在一次提交/推送下.我的工作流程非常简单(除了这件事),添加额外的步骤或复杂的因素会让我很伤心.
If possible, I'd like to keep everything under a single commit/push. My workflow is beautifully simple (except for this one thing), and adding extra steps or complicating factors would make me a sad Moose.
我不知道它是否有帮助,但是我正在使用塔来帮助管理一切.
I don't know if it helps or not, but I'm using Tower to help manage everything.
推荐答案
我为您没有一个非常出色的解决方案,因此,我将为您提供一些选择.
I don't have a completely awesome solution for you, so I will give you a few options to consider.
首先,我过去通过使用单独的分支qa和dev处理过类似的情况.这确实违反了您对单按"的要求.
First, I have addressed similar situations in the past by using separate branches for production, qa and dev. This does violate your desire for "a single push".
第二,如果您真的想将所有内容都保留在一个分支中,则可以使用另一种常用技术,即使用.gitignore排除特定文件,但通过软链接将它们链接到每个工作目录中.变化的文件.大多数操作系统都通过MKLINK命令支持链接,包括OSX,类Unix(Linux,FreeBSD等)和Windows NTFS.
Secondly, if you really want to keep everything in a single branch, you could use another common technique which is to exclude the specific files by using .gitignore, but link to them in each working directory via a soft-link to the varying file. Links are supported in most operating systems, including OSX, Unix-like (Linux, FreeBSD, etc.) and Windows NTFS via the MKLINK command.
要使用链接进行设置,您需要将.htaccess文件重命名为.htaccess-dev,然后将其复制并更新为适用于所有环境的.htaccess-dev和.htaccess-qa.然后,将.htaccess添加到.gitignore中,最后在每个环境上创建指向正确环境的软链接.
To set up using links, you would rename the .htaccess file to be .htaccess-dev and then copy and update it to .htaccess-dev, .htaccess-qa for all your environments. Then, add .htaccess to the .gitignore and finally create soft-links to the correct environment on each of your environments.
例如,如果您的DEV系统是Windows,您会看到类似以下内容的
For example, if your DEV system was Windows, you would see something like:
C:\code\dev-example>ren .htaccess .htaccess-dev
C:\code\dev-example>mklink .htaccess .htaccess-dev
symbolic link created for .htaccess <<===>> .htaccess-dev
C:\code\dev-example>dir
Volume in drive C is Boot
Volume Serial Number is DC8C-D5C9
Directory of C:\code\dev-example
06/02/2014 06:12 PM <DIR> .
06/02/2014 06:12 PM <DIR> ..
06/02/2014 06:09 PM 10 .gitignore
06/02/2014 06:09 PM <SYMLINK> .htaccess [.htaccess-dev]
06/02/2014 06:08 PM 22 .htaccess-dev
06/02/2014 06:12 PM 23 .htaccess-prod
4 File(s) 55 bytes
2 Dir(s) 13,497,245,696 bytes free
C:\code\dev-example>type .htaccess
# Config file for DEV
C:\code\dev-example>type .gitignore
.htaccess
这种方法对于一些不同的配置文件效果很好,但是如果您有很多这样的文件,则变得笨拙,并且不能真正满足您排除.less文件的愿望.
This approach works well for a few varying configuration files, but gets unwieldy if you have many such files, and it doesn't really address your desire for excluding the .less files.
最后,如果您可以重新组织项目以将仅开发人员代码分离到单独的文件夹中,则可以在生产服务器上使用git sparse-checkout来仅捕获您想要的产品文件夹.与使用软链接的配置文件结合使用,这可以使您具有单按式工作流程,同时在dev/qa/prod中维护不同的工作文件夹.参见 http://briancoyner.github.io/blog/2013 /06/05/git-sparse-checkout/
Finally, if you can re-organize your project to separate the dev only code into separate folders, you could use git sparse-checkout on the production server to grab only the folders that you want in prod. In combination with using soft-linked configuration files, this might allow you to have your single-push workflow while maintaining different working folders in dev/qa/prod. See http://briancoyner.github.io/blog/2013/06/05/git-sparse-checkout/
这篇关于在排除一些已提交文件的同时推送到远程服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!