V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
lyf362345
V2EX  ›  git

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

  •  
  •   lyf362345 · 2014-12-16 16:10:12 +08:00 · 4494 次点击
    这是一个创建于 3425 天前的主题,其中的信息可能已经有所发展或是发生改变。
    * @author fengqi <[email protected]>;
    * @version $Id: UploadController.php 9371 2014-11-05 06:56:40Z lyf $

    类似这样, 会自动更新的, 记录版本号。
    第 1 条附言  ·  2014-12-16 18:31:24 +08:00
    忘记说,这个版本是写在文件里面的,可能有人不熟悉 svn,svn 里是一个文件设置了 keyword:id 属性,然后如果文件内注释里写上:
    @version $Id: $
    以后提交就会自动变成这样:
    @version $Id: UploadController.php 9371 2014-11-05 06:56:40Z lyf $
    可以很直观的看到最后一次是谁更改,以及时间(这里的时间没有+8),和版本号
    第 2 条附言  ·  2014-12-16 21:08:59 +08:00
    谢谢大家回复,其实没有,也的确可能是我思维没转变吧,git log -p file 可以查看到文件近期的变动,这样看好了,谢谢大家 :-)
    18 条回复    2014-12-17 20:16:18 +08:00
    helloleo
        1
    helloleo  
       2014-12-16 16:33:27 +08:00
    没有。等你了解 Git 的具体工作机制之后就自然而然知道为什么没有这个所谓的「版本号」了。
    327beckham
        2
    327beckham  
       2014-12-16 18:08:31 +08:00
    一个commit可以算作一个版本?不太了解SVN的机制。
    wwwjfy
        3
    wwwjfy  
       2014-12-16 18:17:54 +08:00
    修改文件内容?写个 pre-commit 的 hook
    lyf362345
        4
    lyf362345  
    OP
       2014-12-16 18:21:35 +08:00   ❤️ 1
    @helloleo 机制我知道一些啊,需要这个版本号只是为了快速定位提交详情,扯不到跟 svn 的差异上去吧
    lyf362345
        5
    lyf362345  
    OP
       2014-12-16 18:22:09 +08:00
    @327beckham 一样的,也是一个 commit 一个版本
    lyf362345
        6
    lyf362345  
    OP
       2014-12-16 18:22:51 +08:00
    @wwwjfy 貌似也可以这样搞,但是 github、gitlab 就比较局限了
    gotounix
        7
    gotounix  
       2014-12-16 18:23:35 +08:00
    写个定时器,实时git pull
    lyf362345
        8
    lyf362345  
    OP
       2014-12-16 18:27:28 +08:00
    @gotounix 没啊,这个 version 是写在文件里面的
    noli
        9
    noli  
       2014-12-16 19:13:24 +08:00
    @lyf362345 每次 commit 不是都会产生一传 字符串的吗,那个就是 git 的版本号,可以快速切换到该版本~~~

    RTFM
    lyf362345
        10
    lyf362345  
    OP
       2014-12-16 19:21:22 +08:00
    @noli 对啊 那也没符合我的需求啊
    banbanchs
        11
    banbanchs  
       2014-12-16 19:22:58 +08:00
    git hook中的commit-msg应该可以办到,不过要自己写脚本
    noli
        12
    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
        13
    noli  
       2014-12-16 19:30:50 +08:00
    你是不是想说 git log
    myrual
        14
    myrual  
       2014-12-16 19:56:04 +08:00
    这种功能其实挺鸡肋的。
    以前做diff的时候就总碰到这种和代码无关但是不得不看的差别。
    lawrencexu
        15
    lawrencexu  
       2014-12-16 20:06:00 +08:00
    svn当初搞出这种鸡肋功能的部分原因可能是集中式VCS,不连服务器就看不到log,窃以为git上就算有这个功能你也不要用了。
    vietor
        16
    vietor  
       2014-12-16 20:14:51 +08:00 via Android
    工具换了,思维没换
    zyxfsky
        17
    zyxfsky  
       2014-12-16 20:23:57 +08:00
    还用同一版本怎么做DVCS
    mckelvin
        18
    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。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2214 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:09 · PVG 18:09 · LAX 03:09 · JFK 06:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.