简体   繁体   English

版本控制工作流程

[英]Version Control Work Flow

I have been coding for over 10 years but I have never used any kind of version control. 我已经编码了10多年,但是我从未使用过任何版本控制。 I am wanting to learn and start using GIT, I intend on reading the Apress ProGIT book soon. 我想学习并开始使用GIT,我打算很快阅读Apress ProGIT书。

This question isn't on how to use the GIT command but more on in which steps to invoke them. 这个问题不是关于如何使用GIT命令,而是关于在哪些步骤中调用它们的问题。

I often read about people saying to checkout a project, then push it to the server. 我经常读到有人说要签出项目,然后将其推送到服务器。

I am usually working on many files at once so I am trying to figure out, everyime I make a change to a file and hit save` is that the time I should commit that file, or is it more like ok I worked on these 5 files today, at the end of the day I can commit all these 5 files? 我通常一次处理多个文件,所以我想弄清楚,我每更改一个文件然后点击保存`,是我应该提交该文件的时间,或者更确定,我从事这5个工作今天的文件,在一天结束时我可以提交所有这5个文件?

I know a lot of people use command line for GIT so I can't imagine them going back and forth every time a fil is changed. 我知道很多人在GIT中使用命令行,所以我无法想象他们每次更改fil后都会来回走动。

I realize this may sound basic and it is but remember I have never used any kind of version control so I am a bit lost, I mean all the articles and tutorials are about the correct syntax/commands and assume you have other version control knowledge (which most people do) 我意识到这听起来很基础,但是记住我从未使用过任何版本控制,所以我有点迷失了,我的意思是所有文章和教程都是关于正确的语法/命令的,并假设您还具有其他版本控制知识(大多数人都这样做)

The thing with git, or any DVCS for that matter, is that committing and pushing your commits upstream are entirely separate notions. git或与此相关的任何DVCS的问题是,向上游提交推送您的提交是完全独立的概念。 If with SVN, for example, committing meant everyone seeing your changeset, in git you have no such worries. 例如,如果使用SVN,则提交意味着每个人都可以看到您的更改集,在git中,您无需担心。 Commit whenever you want, as much as you want. 随时随地进行提交。 Push the changes upstream once you're confident enough with them. 一旦对变更有足够的信心,就将变更推向上游。

This allows you to commit as often as you wish. 这使您可以根据自己的意愿进行提交。 Basically this boils down to your personal workflow preference and that of your team. 基本上,这可以归结为您和团队的个人工作流程偏好。

A good rule of thumb is to commit once you have a stable new version of your code, such that if anyone happens to check out that revision, stuff won't be broken. 一个好的经验法则是,一旦您有了稳定的代码新版本,便要提交,这样,如果有人偶然检出该修订版,则不会破坏任何内容。 (This is also important later on if you plan on doing git bisect , which is an advanced debugging method, but ignore that for now.) (如果您打算执行git bisect ,这在以后也很重要, git bisect是一种高级调试方法,但现在暂时忽略它。)

There are some really good resources that you can learn-by-example from: 您可以通过以下示例学习一些非常好的资源:

I am usually working on many files at once so I am trying to figure out, everyime I make a change to a file and hit save` is that the time I should commit that file, or is it more like ok I worked on these 5 files today, at the end of the day I can commit all these 5 files? 我通常一次处理多个文件,所以我想弄清楚,我每更改一个文件然后点击保存`,是我应该提交该文件的时间,或者更确定,我从事这5个工作今天的文件,在一天结束时我可以提交所有这5个文件?

When working with VCS it's better to think about changes in terms of features (or fixes if you're working on an issue) and not just files. 使用VCS时,最好考虑功能(或解决问题时的修复)方面的变化,而不仅仅是文件。 Even if you changed only one file, but introduced new feature that is complete and, in case you're working in a team, ready to be shared with someone else it's time to make a commit. 即使您只更改了一个文件,但引入了完整的新功能,并且如果您在团队中工作,也准备与其他人共享,那么该进行提交了。 On the other hand if you changed 20 files already, but you are still in the middle of implementing new feature, it's better to postpone commit until you finished. 另一方面,如果您已经更改了20个文件,但是您仍在实施新功能中,最好将提交推迟到完成为止。

Every methodology has exceptions, but it's a general rule I try to use in my work. 每种方法都有例外,但这是我尝试在工作中使用的一般规则。 The idea behind it is that after checking out your code at any commit you get something more or less completed and working. 其背后的想法是,在任何提交中签出代码后,您或多或少地完成了工作。 Creating new commit for every feature is useful as well when you need to remove/revert one of the features later. 当以后需要删除/还原其中一个功能时,为每个功能创建新提交也很有用。 Though, often you are working on a big feature that can't go in a single commit. 但是,通常您正在开发一项无法一次提交的大型功能。 In that case I still try to break this feature into smaller pieces and make commit after completing everyone of them. 在那种情况下,我仍然会尝试将此功能分解为较小的部分,并在完成每个部分之后进行提交。

And the exception for me is usually the project that just have started and you don't care so much about future as it's only beginning and project doesn't have good structure yet and most likely lots of the stuff will change in the nearest future. 对我来说,例外是通常是刚刚开始的项目,您不太关心未来,因为它才刚刚开始并且项目还没有良好的结构,因此很可能在不久的将来会发生很多变化。 In that case my commits sometimes become huge and not that well structured. 在这种情况下,我的提交有时会变得很大,而且结构也不那么好。

Check out this link: Git for beginners: The definitive practical guide 查看此链接: Git初学者:权威的实用指南

I found it very useful. 我发现它非常有用。 It made me understand how it works. 它使我了解它是如何工作的。

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

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