在大型团队中使用单个 CSS 文件和版本控制的方法是什么
我们在 Magento 平台上工作,我们的前端开发人员都在同一个 CSS 样式表上工作。此样式表附带了许多现有样式。大多数时候,我告诉他们将任何其他样式放在底部,以便于合并和其他操作。当您想要将某些样式与样式表中已存在的选择器一起放置时,这并不总是有效。
我们似乎遇到了很多开发人员没有正确管理冲突并覆盖其他人的代码的问题。显然,当您知道其他人已经处理完文件时,最好尝试处理文件,以减少冲突的可能性,但显然,如果有不止一名开发人员在一个网站上工作,而只有一个 CSS 文件,那么就会遇到这种情况很多冲突。
我正在寻找其他人管理这个问题的方法,以及如何最好地减少这些开发人员的冲突的一些想法。
We work on the Magento platform and our front-end developers all work on the same CSS stylesheet. There are a lot of existing styles that come with this stylesheet. Most of the time I tell them to put any additional styles at the bottom to make it easier for merging and everything. This doesn't always work when you want put certain styles with selectors that are already existing in the stylesheet.
We seem to be having a lot of issues with developers not managing conflicts correctly and overriding other peoples code. Obviously its always best to try and work on files when you know others are done with it to lessen the chance of conflicts but obviously if there is more then one developer working on a site and there is only one CSS file this is going to run into a lot of conflicts.
I am looking for ways other people manage this and some ideas for how to best minimize the amount of conflicts these developers have.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有一个 CSS 文件。将一堆小的 CSS 文件合并并缩小为一个文件用于部署,但在开发过程中逻辑上独立的样式。
正如 @JosephMastey 下面所建议的,我个人为网站的每个不同样式的页面分离了一个文件。在样式表中,我倾向于将选择器从更通用到更具体进行排序,并将选择器分组在一起(例如,所有
table#foo ...
选择器都是连续的)。使用合理的选择器像 Git 这样的版本控制系统,不需要您签出或锁定文件,而是允许通过智能合并进行同步编辑。
编辑:在某些时候,您已经培训并信任了您的开发人员。对于那些不断重复彼此的工作并糟糕地合并编辑的开发人员来说,最终能有所帮助的唯一方法就是教导他们不要这样做。
Don't have a single CSS file. Have a bunch of small CSS files that are merged and minified into a single file for deployment but that logically separate styles during development.
As @JosephMastey suggests below, I personally separate one file per differently-styled page of the site. Within stylesheets I tend to order selectors from more-general to more specific, and group selectors together (e.g. all
table#foo ...
selectors are contiguous).Use a sane version-control system like Git that does not require you to check out or lock files, but instead allows simultaneous edits with intelligent merges.
Edit: And at some point you have train and trust your developers. The only method that will ultimately help with developers who are repeatedly running over each others' work and merging their edits badly is teaching them not to do so.
如果每个人都在编辑文件的同一部分(即末尾),则出现编辑冲突的可能性会大大增加。
我想说让 CSS 自然地去哪里。如果某人正在编辑一个部分,而其他人正在编辑整个其他部分,那么任何像样的版本控制系统都会在有人更新时自动合并大部分更改,并且冲突会更少。
Your chance of edit conflicts increases dramatically if everyone's editing the same part of the file (namely, the end).
I'd say let the CSS go where it goes naturally. If someone's editing one part and someone else is editing a whole other section, any decent revision control system will merge most of the changes automatically when someone updates, and there will be fewer conflicts.
我同意“没有一个 CSS 文件”的观点。 Magento 模块每个都可以有自己的样式表,当然您已经将不相关的任务分离到独立的模块中,不是吗?如果 Magento 附带单独的目录表、结帐表、客户表等,我会更喜欢它。但遗憾的是它没有,你必须自己做,也许用它们准备一个空白主题。
根据开发人员的说法,将其拆分没有意义。开发人员来来去去,并被分配不同的任务。
Magento 还包括 CSS 和 CSS JS 合并,因此您无需担心有很多工作表。有 Fooman Speedster 和 mod_pagespeed 以及。
I concur on the "Don't have a single CSS file" sentiment. Magento modules can each have their own stylesheet(s), and of course you already separate unrelated tasks into independent modules don't you? I would prefer it if Magento came with separate sheets for catalog, checkout, customer, etc. but sadly it does not, you'll have to do that yourself and maybe prepare a blank theme with them.
It doesn't make sense to break it up according to developers. Devs come and go and are assigned different tasks.
Magento also includes CSS & JS merging so you don't need to worry about having many sheets. There is Fooman Speedster and mod_pagespeed as well.
根据我的经验,应该由一名开发人员负责该项目,直到该项目足够成熟以允许外部帮助为止。该单个开发人员应该设置在整个应用程序中使用的指南和标准样式,以便人们不需要为每个元素添加新样式。尝试让最初的开发人员在最初添加到存储库时检查所有新的样式表更改,以便项目的新开发人员了解现有的实用程序类或约定。
如果您总是从某种库存系统主题开始,这也会有所帮助 - 这样人们就知道每个项目开始时的分数,并且没有借口搞乱您组织的 CSS :)
正如 @cHao 指出的,当一大群开发人员参与时,请确保他们永远不会直接添加到文件末尾。这是我们经历过的冲突的最大原因,而且很容易避免。
In my experience, a single developer should be working on the project until it matures enough to allow for outside help. That single developer should set guidelines and standard styles to be used throughout the application, so that people need not add a new style for each element. Try and have the initial developer review all new stylesheet changes as they're added to the repository initially, so that developers that are new to the project are made aware of utility classes, or conventions, that exist.
It would also help if you had some kind of stock system theme that you always start with -- that way people know the score at the start of each project and have no excuse to mess up your organised CSS :)
As @cHao points out, when a whole bunch of developers get involved make sure they never add directly to the end of the file. That's the single biggest cause of conflicts that we experience and can be easily avoided.