从CVS迁移到Git:相当于$ Id $? [英] Moving from CVS to Git: $Id$ equivalent?
问题描述
我通读了一系列有关简单源代码控制工具的问题,Git似乎是一个合理的选择。我已经启动并运行它,到目前为止效果很好。我喜欢CVS的一个方面是版本号的自动递增。
I read through a bunch of questions asking about simple source code control tools and Git seemed like a reasonable choice. I have it up and running, and it works well so far. One aspect that I like about CVS is the automatic incrementation of a version number.
我知道在分布式存储库中这没什么意义,但是作为开发人员,我想/需要这样的东西。让我解释一下原因:
I understand that this makes less sense in a distributed repository, but as a developer, I want/need something like this. Let me explain why:
我使用Emacs。我会定期查看并查找第三方软件包的Lisp源文件的新版本。假设我有一个文件foo.el,根据标题,该文件的版本为1.3;如果我查找最新版本并看到它是1.143或2.6或其他值,我知道我已经远远落后了。
I use Emacs. Periodically I go through and look for new versions of the Lisp source files for third-party packages. Say I've got a file, foo.el, which, according to the header, is version 1.3; if I look up the latest version and see it's 1.143 or 2.6 or whatever, I know I'm pretty far behind.
如果相反,我看到几个40个字符哈希,我将不知道是哪一个以后,也不会知道以后有多少。如果我不得不手动检查ChangeLogs以了解我的过时状况,我绝对会讨厌它。
If instead I see a couple of 40-character hashes, I won't know which is later or get any idea of how much later it is. I would absolutely hate it if I had to manually check ChangeLogs just to get an idea of how out of date I am.
作为一名开发人员,我想表达一下这种礼貌。就像我看到的那样,发给使用我的输出的人员(也许我在自欺欺人,但让我们暂时搁置一旁)。我不想记住自己每次都要增加该死的数字,或者是一个时间戳或类似的东西。那是一个真正的PITA,我从经验中知道。
As a developer, I want to extend this courtesy, as I see it, to the people that use my output (and maybe I'm kidding myself that anyone is, but let's leave that aside for a moment). I don't want to have to remember to increment the damn number myself every time, or a timestamp or something like that. That's a real PITA, and I know that from experience.
那我有什么选择?如果我无法获得等价的$ Id:$,我还能如何提供所需的内容?
So what alternatives do I have? If I can't get an $Id:$ equivalent, how else can I provide what I'm looking for?
我应该提一下,我的期望是最终用户将没有安装Git,即使安装了Git,也将没有本地存储库(实际上,我希望不要以这种方式使它可用)。
I should mention that my expectation is that the end user will NOT have Git installed and even if they do, will not have a local repository (indeed, I expect not to make it available that way).
推荐答案
SHA只是版本的一种表示形式(尽管是规范的)。 git describe
命令提供了其他功能并且效果很好。
The SHA is just one representation of a version (albeit canonical). The git describe
command offers others and does so quite well.
例如,当我运行 git describe
在我的 Java memcached客户端的主分支中来源,我得到这个:
For example, when I run git describe
in my master branch of my Java memcached client source, I get this:
2.2-16-gc0cd61a
这说明了两个重要的事情:
That says two important things:
- 其中恰好有16次提交此树自2.2起
- exact 源树可以显示在其他任何人的克隆上。
- There have been exactly 16 commits in this tree since 2.2
- The exact source tree can be displayed on anyone else's clone.
例如,您将版本
文件与源文件打包在一起(甚至重写了所有要分发的内容)以显示该数字。假设打包版本为 2.2-12-g6c4ae7a
(不是发行版,而是有效版本)。
Let's say, for example, you packaged a version
file with the source (or even rewrote all the content for distribution) to show that number. Let's say that packaged version was 2.2-12-g6c4ae7a
(not a release, but a valid version).
现在,您可以确切地看到您落后了多远(4次提交),和,您可以确切地看到其中4次提交:
You can now see exactly how far behind you are (4 commits), and you can see exactly which 4 commits:
# The RHS of the .. can be origin/master or empty, or whatever you want.
% git log --pretty=format:"%h %an %s" 2.2-12-g6c4ae7a..2.2-16-gc0cd61a
c0cd61a Dustin Sallings More tries to get a timeout.
8c489ff Dustin Sallings Made the timeout test run on every protocol on every bui
fb326d5 Dustin Sallings Added a test for bug 35.
fba04e9 Valeri Felberg Support passing an expiration date into CAS operations.
这篇关于从CVS迁移到Git:相当于$ Id $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!