git提交最佳实践 [英] git commit best practices
问题描述
我使用git来管理一个C ++项目。当我在处理这些项目时,我发现很难在更改与许多地方相关的事物时将更改组织为提交。例如,我可能会改变 .h
文件中的类接口,这会影响相应的<$ c $ c> .cpp
文件以及其他使用它的文件。我不确定把所有的东西放到一个大的提交中是否合理。
直觉上,我认为提交应该是模块化的,每一个都对应一个功能更新/更改,以便协作者可以相应地选择一些内容。但似乎有时包含大量文件和更改以实现功能更改是不可避免的。
搜索没有给我任何好的建议或提示。因此我想知道是否有人可以在提交时给我一些最佳实践。
PS。我一直在使用git一段时间,我知道如何交互添加/ rebase / split / amend / ...我所要求的是哲学部分。
更新:感谢所有的建议。也许这应该从练习中学到。我会在一段时间内保持这个问题,看看是否有更多的建议。
我倾向于按照你的建议提交:一个提交是一个逻辑连接的变更集。我的提交可以是从单行程到所有文件更改(例如在源文件中添加/更改版权声明)的任何内容。改变的原因不一定是我正在执行的全部任务,但它通常是任务中的里程碑。
如果我修改了一些与我目前的提交,我倾向于做一个交互式添加来分隔不相关的变化 - 即使它是一个空白整理。
我发现提交只需将工作状态转储到存储库使其不太适用:我不能将bug修复移植到较早的版本,或者如果提交遍布整个地方,则很容易在其他分支中包含实用程序功能。
这种方法的一种替代方法是在特征分支中使用很多微小的提交,并且一旦完成整个特性,就可以重写历史重写以将提交整理为逻辑结构。但我觉得这种做法是浪费时间的。
I am using git to manage a C++ project. When I am working on the projects, I find it hard to organize the changes into commits when changing things that are related to many places.
For example, I may change a class interface in a .h
file, which will affect the corresponding .cpp
file, and also other files using it. I am not sure whether it is reasonable to put all the stuff into one big commit.
Intuitively, I think the commits should be modular, each one of them corresponds to a functional update/change, so that the collaborators could pick things accordingly. But seems that sometimes it is inevitable to include lots of files and changes to make a functional change actually work.
Searching did not yield me any good suggestion or tips. Hence I wonder if anyone could give me some best practices when doing commits.
PS. I've been using git for a while and I know how to interactively add/rebase/split/amend/... What I am asking is the PHILOSOPHY part.
Update: Thanks for all the advices. Maybe this should be learned from practicing. I will keep the problem open for some time to see if there is more suggestions.
I tend to commit as you propose: a commit is a logically connected change set. My commits can be anything from a one-liner to a change in all files (for example add/change a copyright notice in the source files). The reason for change need not be a full task that I am implementing, but it is usually a milestone in the task.
If I have modified something that is not related to my current commit, I tend to do an interactive add to separate out the unrelated changes, too - even when it is a whitespace tidy up.
I have found that commits that simply dump the working state to repository makes them a lot less useful: I cannot backport a bugfix to an earlier version or include a utility functionality in another branch easily if the commits are all over the place.
One alternative to this approach is using a lot of tiny commits inside a feature branch, and once the whole feature is done, do heavy history rewriting to tidy up the commits into a logical structure. But I find this approach to be a time waster.
这篇关于git提交最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!