Git 有类似 Svn 的 version 自动更新的属性么

2014-12-16 16:10:12 +08:00
 lyf362345
* @author fengqi <lyf362345@gmail.com>
* @version $Id: UploadController.php 9371 2014-11-05 06:56:40Z lyf $

类似这样, 会自动更新的, 记录版本号。
4512 次点击
所在节点    git
18 条回复
helloleo
2014-12-16 16:33:27 +08:00
没有。等你了解 Git 的具体工作机制之后就自然而然知道为什么没有这个所谓的「版本号」了。
327beckham
2014-12-16 18:08:31 +08:00
一个commit可以算作一个版本?不太了解SVN的机制。
wwwjfy
2014-12-16 18:17:54 +08:00
修改文件内容?写个 pre-commit 的 hook
lyf362345
2014-12-16 18:21:35 +08:00
@helloleo 机制我知道一些啊,需要这个版本号只是为了快速定位提交详情,扯不到跟 svn 的差异上去吧
lyf362345
2014-12-16 18:22:09 +08:00
@327beckham 一样的,也是一个 commit 一个版本
lyf362345
2014-12-16 18:22:51 +08:00
@wwwjfy 貌似也可以这样搞,但是 github、gitlab 就比较局限了
gotounix
2014-12-16 18:23:35 +08:00
写个定时器,实时git pull
lyf362345
2014-12-16 18:27:28 +08:00
@gotounix 没啊,这个 version 是写在文件里面的
noli
2014-12-16 19:13:24 +08:00
@lyf362345 每次 commit 不是都会产生一传 字符串的吗,那个就是 git 的版本号,可以快速切换到该版本~~~

RTFM
lyf362345
2014-12-16 19:21:22 +08:00
@noli 对啊 那也没符合我的需求啊
banbanchs
2014-12-16 19:22:58 +08:00
git hook中的commit-msg应该可以办到,不过要自己写脚本
noli
2014-12-16 19:28:50 +08:00
@lyf362345 会英文的就看这里。

http://git-scm.com/book/en/v2/Getting-Started-Git-Basics#Git-Has-Integrity

好吧,哥顺手给你翻译了

Git Has Integrity

Git 可以保证数据完整性

Everything in Git is check-summed before it is stored and is then referred to by that checksum. This means it’s impossible to change the contents of any file or directory without Git knowing about it. This functionality is built into Git at the lowest levels and is integral to its philosophy. You can’t lose information in transit or get file corruption without Git being able to detect it.

所有git 存储的东西都是经过校验之后再存储的,然后产生的校验码可以用来作为索引。这就是说,试图修改文件或文件夹的内容而又不让git 知道是不可能的。校验这个功能是在git 的底层完成的,并且融入到git 的哲学当中。你不会在git 没有侦测到的情况下,因为传输或者获取文件的过程中而造成信息丢失。

The mechanism that Git uses for this checksumming is called a SHA-1 hash. This is a 40-character string composed of hexadecimal characters (0–9 and a–f) and calculated based on the contents of a file or directory structure in Git. A SHA-1 hash looks something like this:

Git 用于校验的是 SHA-1 哈希函数。在Git 中,基于文件或者文件夹结构内容进行计算,得出一个40个字符组成的16进制字符串。一个SHA-1 哈希字符串看上去是这样的。

24b9da6552252987aa493b52f8696cd6d3b00373


You will see these hash values all over the place in Git because it uses them so much. In fact, Git stores everything in its database not by file name but by the hash value of its contents.

你会在git 的每一处都看着这些哈希值,因为它使用得非常频繁。事实上,git吧所有东西存到数据库里面的时候使用的不是文件名而是这些存储内容的哈希值。
noli
2014-12-16 19:30:50 +08:00
你是不是想说 git log
myrual
2014-12-16 19:56:04 +08:00
这种功能其实挺鸡肋的。
以前做diff的时候就总碰到这种和代码无关但是不得不看的差别。
lawrencexu
2014-12-16 20:06:00 +08:00
svn当初搞出这种鸡肋功能的部分原因可能是集中式VCS,不连服务器就看不到log,窃以为git上就算有这个功能你也不要用了。
vietor
2014-12-16 20:14:51 +08:00
工具换了,思维没换
zyxfsky
2014-12-16 20:23:57 +08:00
还用同一版本怎么做DVCS
mckelvin
2014-12-17 20:16:18 +08:00
今天做了件类似的事情,每次commit的时候,在python的某个module里自动更新 `__version__`。参考了:

http://mass-communicating.com/code/2013/11/08/python-versions.html

需要注意的是,这个 `__version__` 的值和git的版本号是不一样的,毕竟你无法在一个文件里写下这个文件的hash。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/154356

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX