简体   繁体   English

一些基本的版本控制问题

[英]A few basic version control questions

... which I didn't feel like splitting into several question posts, since I guess, them being basic, most people here will know how to answer. ...我不想分成几个问题帖子,因为我猜,它们是基本的,这里的大多数人都知道如何回答。

I've been developing for several years now, and I've never had the time to learn about version control. 我已经开发了好几年了,我从来没有时间去学习版本控制。 Renaming directories with different version names always seemed enough. 重命名具有不同版本名称的目录似乎总是足够的。 Now, I've finally decided to learn it, but some basic terminology and working principles still confuse me. 现在,我终于决定学习它,但是一些基本的术语和工作原理仍然让我感到困惑。

My projects are relatively small, up to 10 or so files (although the files are relatively big), and are done in non-OO way. 我的项目相对较小,最多10个文件(虽然文件相对较大),并且以非OO方式完成。 I often take one approach, do it to some point, then decide that that will not do, then (reusing old code) completely rewrite the whole project with completely different file organization, and internal code organization. 我经常采取一种方法,在某种程度上做到这一点,然后决定那样做,然后(重用旧代码)用完全不同的文件组织和内部代码组织完全重写整个项目。 File dissapearing and new files appearing between those "versions" are not uncommon. 文件消失和出现在这些“版本”之间的新文件并不罕见。

So here are my "confusions": 所以这是我的“困惑”:
1) for example, as described, I've putted the first version into vc. 1)例如,如上所述,我已将第一个版本推入vc。 Then I delete all files, and rewrite them anew. 然后我删除所有文件,并重新重写它们。 If I understood well, that would be a new "branch", right ? 如果我理解得很好,那将是一个新的“分支”,对吧?
2) if I continue developing that version, I would just keep commiting to that "branch" ? 2)如果我继续开发该版本,我会继续致力于那个“分支”吗?
3) does vc save, when saving a save-point in a branch, all files in, or does it just save the difference between them? 3)vc保存,当在分支中保存保存点时,所有文件都在,或者只是保存它们之间的差异?
4) can I easily get all (whole project) files from a certain save-point in a branch, or do I have to follow it up through diff's until the beginning ? 4)我可以轻松地从分支中的某个保存点获取所有(整个项目)文件,还是我必须通过差异来跟踪它直到开始? (I just want to be able to say, "here, this is the save-point - copy all files you need so it looks like this") (我只想说,“这里,这是保存点 - 复制你需要的所有文件,所以它看起来像这样”)
5) what does it mean, in very simple-terms, to "push" and "pull". 5)用非常简单的术语来说,“推”和“拉”是什么意思。 I don't understand the difference between "push"/"pull" and "commit". 我不明白“推”/“拉”和“提交”之间的区别。

If it matters, I'm using VS 2008, and am thinking of using git-extensions, for I've heard nice stuff about it. 如果重要的话,我正在使用VS 2008,并且正在考虑使用git-extensions,因为我听说过很好的东西。 Is it a good combination, and would using SVN (for example VisualSvn or Ankh) be a better option for me, considering the above? 它是一个很好的组合,考虑到上述情况,使用SVN(例如VisualSvn或Ankh)对我来说是更好的选择吗?

-- with regards, Peter - 关心,彼得

Part of your confusion probably comes from different version control systems (VCSs) that use terminology differently. 您的部分困惑可能来自不同版本控制系统(VCS),它们使用不同的术语。

I usually think of code in "lines". 我通常会想到“行”中的代码。 I start with the original version of a file, and save it to my version control system. 我从文件的原始版本开始,并将其保存到我的版本控制系统。 Putting it into the VCS is called a "check-in". 将其放入VCS称为“签到”。 The version control system tags it with some number, such as revision 1.0. 版本控制系统用一些数字标记它,例如1.0版。 Now I compile my software. 现在我编译我的软件。 It breaks, so I have to edit it. 它坏了,所以我必须编辑它。 To do that, I "check it out" of the version control system and edit it. 为此,我“检查”版本控制系统并进行编辑。 Now that it's fixed, I check it back in and the version control system stores it as revision 1.1. 现在它已修复,我将其重新检入并且版本控制系统将其存储为修订版1.1。 My boss wants a new feature, so I check it out, edit it, and check it back in again, and it's stored as revision 1.2. 我的老板想要一个新功能,所以我检查出来,编辑它,然后再次检查它,它被存储为修订版1.2。

That's the "main line" or "trunk" of code. 这是代码的“主线”或“主干”。

A version control system will let you get any old version of a file by specifying the revision number. 通过指定版本号,版本控制系统将允许您获取文件的任何旧版本。 Let's say I get a bug report from software based on revision 1.1. 假设我从基于修订版1.1的软件获得错误报告。 I can use "diff" or any comparison tool to compare 1.1 with 1.0 and see what changed. 我可以使用“diff”或任何比较工具来比较1.1和1.0,看看有什么变化。 It doesn't matter how the version control system stores it internally, I just ask for it by revision number and I get the whole file. 版本控制系统如何在内部存储它并不重要,我只是通过修订号询问它,我得到整个文件。

The next thing to understand is that a group of files makes up your project or solution. 接下来要理解的是,一组文件构成了您的项目或解决方案。 When you're going to compile your software to release it to the world, you want to associate a "label" with all of those files so you can treat them all as a group. 当您要编译软件以将其发布到全世界时,您希望将“标签”与所有这些文件相关联,以便您可以将它们全部视为一个组。 Most people use a numeric label, such as Windows 3.0, Windows 3.51, etc., but that's just convention. 大多数人使用数字标签,如Windows 3.0,Windows 3.51等,但这只是惯例。 You could label a version "hardy heron" or "gutsy gibbon" if you want. 如果你愿意,你可以标记一个版本“hardy heron”或“gutsy gibbon”。

Now, this is all fine if you're one guy who just keeps updating things as you go along. 现在,如果你是一个随时随地不断更新的人,这一切都很好。 But let's say you keep working on your software, and release version 7, then 8, then 9, and now you're working on version 10. But today you get a serious bug report on version 7 that you just have to fix. 但是,假设您继续使用您的软件,然后发布版本7,然后是8版本,然后是9版本,现在您正在使用版本10.但是今天您将收到有关版本7的严重错误报告,您只需要修复它。 So you go to your VCS and request all the source files with the label "version 7". 因此,您转到VCS并请求标签为“版本7”的所有源文件。 You get those into a separate folder on your disk, and fix the bug. 您可以将它们放入磁盘上的单独文件夹中,并修复该错误。 But when you go to check those files in, you need them to be a part of version 7 because you've already added features in versions 8 and 9. This is when you create a "branch". 但是当你去检查那些文件时,你需要它们成为版本7的一部分,因为你已经在版本8和9中添加了功能。这就是你创建一个“分支”。

An example might be clearer. 一个例子可能更清楚。 Let's say you checked out "version 7" of the package, and the file to fix was at revision 1.23. 假设你检查了包的“版本7”,要修复的文件是修订版1.23。 In version 10 (which you're working on in a different folder) you're working with revision 1.40. 在版本10(您正在另一个文件夹中工作),您正在使用版本1.40。 You don't want the changes for version 7 to go into 1.41, because that would overwrite and destroy all the neat features you added in revisions 1.24 thru 1.40. 您不希望版本7的更改进入1.41,因为这会覆盖并破坏您在修订版1.24至1.40中添加的所有简洁功能。 So you create a branch, and check in your changed file as revision 1.23.0.1. 因此,您创建一个分支,并将更改的文件签入为修订版1.23.0.1。 You compile it, and now the bug is fixed. 你编译它,现在修复了错误。 And now you have to release it to your customers. 现在您必须将其发布给您的客户。 When you release, you create a new label. 发布时,您将创建一个新标签。 I'd label this something like "version 7.1" so that I could tell the difference between the broken software and the fixed software. 我将这个标记为“版本7.1”,这样我就能分辨出破碎的软件和固定软件之间的区别。 And I'd know that it didn't have all the features of versions 8+. 而且我知道它没有版本8+的所有功能。

If you plot those software versions on a line, you'd think of a number line going straight from 1 to 10. Where does 7.1 fit on to this line? 如果你在一条线上绘制这些软件版本,你会想到一条直线从1到10的数字线.7.1适合这条线? It sticks out the side, like a branch sticks out from the trunk of a tree. 它伸出一边,就像树枝从树干伸出一样。 That's where we get the names of "branch" and "trunk" from. 这就是我们得到“分支”和“主干”的名称。

我认为你(以及任何不太了解版本控制的人)应该阅读Eric Sink关于这个主题的文章

You don't really need a branch unless you need to work separately on two different sets of code for the same project. 除非您需要为同一个项目分别处理两组不同的代码,否则您不需要分支。 Branching is much more common in a team setting where most developers would be working on longer term features in the trunk, while one or two create a branch to release a specific feature earlier. 分支在团队环境中更为常见,其中大多数开发人员将在中继中处理长期功能,而一个或两个创建分支以更早地发布特定功能。 They would then merge that branch back into the trunk, so all of the code was in one place again. 然后,他们会将该分支合并回主干,因此所有代码都在一个地方。 This is just one example... 这只是一个例子......

My recommendation is just to set up a Subversion repository (ideally on a different server, but if it has to be on your machine, it's better than nothing), and commit (push) your changes there. 我的建议只是建立一个Subversion存储库(理想情况下是在不同的服务器上,但如果它必须在你的机器上,它总比没有好),并在那里提交(推送)你的更改。 You can always update your local working copy (pull) from the repository. 您始终可以从存储库更新本地工作副本(pull)。

Subversion does a binary diff on files, so it only saves the difference, not a whole copy. Subversion对文件执行二进制diff,因此它只保存差异,而不是整个副本。 This can be a problem if you have a lot of renames/deletes (esp. directories) in branches, but should be okay if you stay in the trunk. 如果你在分支中有很多重命名/删除(特别是目录),这可能是一个问题,但如果你留在主干中应该没问题。

If you are worried about those issues, then I recommend Mercurial or Git, which create (clone) entire copies of the repository (no binary diffs). 如果你担心这些问题,那么我推荐Mercurial或Git,它创建(克隆)存储库的整个副本(没有二进制差异)。 Mercurial has a slightly better Windows UI right now, if you are a GUI guy. 如果你是一个GUI人,Mercurial现在有一个稍好的Windows用户界面。 However, Mercurial and Git don't have the same integrated tooling that svn does yet (with Ankh, for example). 但是,Mercurial和Git没有与svn相同的集成工具(例如Ankh)。

I use svn with Ankh for VS2008, and in general, I love it (especially Ankh!), though I've been burned by the directory delete/rename issue in svn a few times... 我使用svn和Ankh for VS2008,一般来说,我喜欢它(特别是Ankh!),虽然我已经被svn中的目录删除/重命名问题烧了几次......

Good luck! 祝好运!

Noah 诺亚

  1. Incorrect, that would simply be a new revision. 不正确,这只是一个新版本。 Branching is where your revision flow "forks" in two or more directions. 分支是您的修订流程在两个或多个方向上“分叉”的位置。 This is generally a special operation distinct from adding and removing files. 这通常是一种特殊操作,与添加和删除文件不同。

  2. As before, you haven't branched at this point. 和以前一样,你还没有分支。 Generally you select which branch you're on using your version control tool. 通常,您使用版本控制工具选择正在使用的分支。 I'd highly recommend looking at the documentation around branching for whichever tool you wish to use. 我强烈建议您查看有关您希望使用的任何工具的分支文档。

  3. Most versin control tools only save the differences between versions of a file. 大多数versin控件工具只保存文件版本之间的差异。 Some (notably CVS) will only do this for text files and changes to binary files will result in a full copy of the new version being stored. 有些(特别是CVS)只对文本文件执行此操作,对二进制文件的更改将导致存储新版本的完整副本。 Note that this doesn't preclude you from getting the full file at any given revision, it's purely a matter of how the data is stored. 请注意,这并不妨碍您在任何给定的版本中获取完整文件,这完全取决于数据的存储方式。

  4. You can get the full state at any selected revision at any time. 您可以随时在任何选定的修订版中获得完整状态。

  5. With a centralised version control system (CVS, Subversion) you commit to the repository and check out from the repository. 使用集中式版本控制系统(CVS,Subversion),您可以提交到存储库并从存储库中检出。 With a decentralised version control system (git, mercurial, darcs, bazaar) you clone a remote repository (or create your own local repository), commit changes to that repository and then you can push changesets to a different remote repository or pull changesets from a remote repository. 使用分散版本控制系统(git,mercurial,darcs,bazaar),您可以克隆远程存储库(或创建自己的本地存储库),提交对该存储库的更改,然后您可以将更改集推送到其他远程存储库或从中提取更改集远程存储库。 The distinction is that each developer has their own copy of the repository and is generating changesets in their copy and for other people to see them these changesets need to be pushed out to a common place from where the other people can pull them. 区别在于每个开发人员都有自己的存储库副本,并在其副本中生成更改集,并且其他人可以看到这些更改集需要被推送到其他人可以从中拉出它们的公共位置。 IBM has a decent introduction to the distributed version control concept. IBM对分布式版本控制概念有了不错的介绍

我相信你会发现这一点很有见地: Windows上的Git图解指南

1) Branches are entirely under your control, the SC system won't surprise you with them (except for multiple heads in distributed sytems, but your example should not cause this.) Now, if you are doing a major reorganization, you might choose to create a new branch so you can easily keep them separate, but it's your choice. 1)分支完全在你的控制之下,SC系统不会让你感到惊讶(除了分布式系统中的多个头,但你的例子不应该导致它。)现在,如果你正在进行重大的重组,你可能会选择创建一个新分支,以便您可以轻松地将它们分开,但这是您的选择。

2) If you choose to use branches, you could continue to develop whichever one you like. 2)如果您选择使用分支机构,您可以继续开发您喜欢的分支机构。 So long as yout changes are committed, you have your checkpoint and can move between them freely. 只要您提交了更改,您就拥有了检查点,并且可以在它们之间自由移动。 In some cases you can even share changes between them, but I wouldn't get into this right off. 在某些情况下,您甚至可以在它们之间共享更改,但我不会立即进行此操作。

3&4) Most systems will save differences as a matter of space economy, but it is an implementation detail. 3&4)大多数系统将节省差异作为空间经济的问题,但它是一个实施细节。 You can retrieve any version at any time, exactly as it was committed. 您可以随时检索任何版本,与提交时完全相同。

5) Commit is setting a checkpoint which you can return to later. 5) Commit正在设置一个检查点,您可以稍后返回。 Push and pull refer to sharing of changes between you and another server or repository; Pushpull指的是你和另一台服务器或存储库之间变化的共享; push is you sending changes somewhere, pull is downloading someone else's work. 推送是你在某处发送更改,拉下载别人的工作。 Centralized systems like Subversion imply push with commit, and require you to be up to date with 'pulls'. 像Subversion这样的集中式系统意味着推送提交,并要求您与“拉动”保持同步。 Distributed systems allow (and require) you to do each part separately. 分布式系统允许(并要求)您单独执行每个部分。

1) for example, as described, I've putted the first version into vc. 1)例如,如上所述,我已将第一个版本推入vc。 Then I delete all files, and rewrite them anew. 然后我删除所有文件,并重新重写它们。 If I understood well, that would be a new "branch", right ? 如果我理解得很好,那将是一个新的“分支”,对吧?

You are correct in thinking that a rewrite should be treated as a new branch, but you will have to tell your version control system that you are creating a new branch. 您认为重写应被视为新分支是正确的,但您必须告诉您的版本控制系统您正在创建新分支。

2) if I continue developing that version, I would just keep commiting to that "branch" ? 2)如果我继续开发该版本,我会继续致力于那个“分支”吗?

Yes. 是。

3) does vc save, when saving a save-point in a branch, all files in, or does it just save the difference between them? 3)vc保存,当在分支中保存保存点时,所有文件都在,或者只是保存它们之间的差异?

I believe most version control systems store deltas between revisions instead of the entire files in order to conserve disk space. 我相信大多数版本控制系统都会在修订版本之间存储增量而不是整个文件,以节省磁盘空间。

4) can I easily get all (whole project) files from a certain save-point in a branch, or do I have to follow it up through diff's until the beginning ? 4)我可以轻松地从分支中的某个保存点获取所有(整个项目)文件,还是我必须通过差异来跟踪它直到开始? (I just want to be able to say, "here, this is the save-point - copy all files you need so it looks like this") (我只想说,“这里,这是保存点 - 复制你需要的所有文件,所以它看起来像这样”)

Most version control systems will allow you to check out any revision. 大多数版本控制系统将允许您检查任何修订。

5) what does it mean, in very simple-terms, to "push" and "pull". 5)用非常简单的术语来说,“推”和“拉”是什么意思。 I don't understand the difference between "push"/"pull" and "commit". 我不明白“推”/“拉”和“提交”之间的区别。

Distributed version control systems have "push" and "pull" commands to upload or download changes to a remote server and the "commit" command to save changes to the local repository. 分布式版本控制系统具有“推”和“拉”命令以将更改上载或下载到远程服务器,并具有“提交”命令以将更改保存到本地存储库。 This contrasts with SVN, which only stores revision information on the server side, so with SVN you "commit" to the remote server. 这与SVN形成对比,SVN仅在服务器端存储修订信息,因此使用SVN可以“提交”到远程服务器。

I'll try to answer your questions in turn. 我会尝试依次回答你的问题。

1) for example, as described, I've putted the first version into vc. 1)例如,如上所述,我已将第一个版本推入vc。 Then I delete all files, and rewrite them anew. 然后我删除所有文件,并重新重写它们。 If I understood well, that would be a new "branch", right ? 如果我理解得很好,那将是一个新的“分支”,对吧?

Deleting the files and rewriting from scratch is not the hallmark of a branch. 删除文件并从头开始重写不是分支的标志。 Think of a trunk and a branch. 想想一个主干和一个分支。 A common pattern is to keep the code for ongoing (latest and greatest) development in the trunk. 一种常见的模式是保持代码在中继中进行持续(最新和最大)的开发。 Then at some point in time, you'll want to release your code at which time you'll take a snap shot of the trunk. 然后在某个时间点,您将要释放您的代码,此时您将拍摄主干的快照。 This snap shot is the branch. 这个快照是分支。

2) if I continue developing that version, I would just keep commiting to that "branch" ? 2)如果我继续开发该版本,我会继续致力于那个“分支”吗?

Yes, you can keep developing the code in the trunk and code in the branch independently. 是的,您可以继续独立开发代码中的代码和分支中的代码。

3) does vc save, when saving a save-point in a branch, all files in, or does it just save the difference between them? 3)vc保存,当在分支中保存保存点时,所有文件都在,或者只是保存它们之间的差异?

From your point of view just think of the branch as a snap-shot, not as a sequence of diffs. 从你的角度来看,只需将分支视为快照,而不是作为一系列差异。 Internally, different products implement the branches in different ways, but you need not concern yourself with this. 在内部,不同的产品以不同的方式实现分支,但您不必担心这一点。

4) can I easily get all (whole project) files from a certain save-point in a branch, or do I have to follow it up through diff's until the beginning ? 4)我可以轻松地从分支中的某个保存点获取所有(整个项目)文件,还是我必须通过差异来跟踪它直到开始? (I just want to be able to say, "here, this is the save-point - copy all files you need so it looks like this") (我只想说,“这里,这是保存点 - 复制你需要的所有文件,所以它看起来像这样”)

To reiterate, think of a branch as a snap-shot of files. 重申一下,将分支视为文件的快照。

5) what does it mean, in very simple-terms, to "push" and "pull". 5)用非常简单的术语来说,“推”和“拉”是什么意思。 I don't understand the difference between "push"/"pull" and "commit". 我不明白“推”/“拉”和“提交”之间的区别。

Systems such as sccs, cvs, svn, perforce, clearcase maintain a central repository for the assets. 诸如sccs,cvs,svn,perforce,clearcase之类的系统维护着资产的中央存储库。 Users push their local copies into the repository. 用户其本地副本送到存储库中。 In svn, this is done using 'svn commit'. 在svn中,这是使用'svn commit'完成的。 Systems such as git and mercurial maintain a distributed repository of assets, and the user pulls files from other repositories to update their own repository. 诸如git和mercurial之类的系统维护分布式资产存储库,用户从其他存储库中提取文件以更新自己的存储库。

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

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