从 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,即使他们安装了,也不会拥有本地存储库(实际上,我希望不会以这种方式提供它).
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:
- 自 2.2 以来,在这棵树中正好有 16 次提交
- 精确源代码树可以显示在任何其他人的克隆上.
- There have been exactly 16 commits in this tree since 2.2
- The exact source tree can be displayed on anyone else's clone.
比方说,例如,您将version
文件与源一起打包(甚至重写了所有内容以进行分发)以显示该编号.假设打包版本是 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屋!