V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
Elethom
V2EX  ›  分享创造

一鍵更新所有項目 LICENSE 的 Copyright 時間( Shell Command)

  •  1
     
  •   Elethom ·
    Elethom · 2016-01-01 15:19:06 +08:00 · 3361 次点击
    这是一个创建于 3030 天前的主题,其中的信息可能已经有所发展或是发生改变。

    http://blog.projectrhinestone.org/one-liner-for-changing-all-git-repos-license-times/

    pwd=$(pwd);for file in ~/GitHub/*/LICENSE;do cd $(dirname $file);git checkout master;stash=$(git diff LICENSE);if [ -n "$stash" ];then git stash;fi;sed -i "" -e "s/\(Copyright (c) \)[0-9]\{4\}\(-[0-9]\{4\}\)*/\1$(git log $(git log --pretty=format:%H|tail -1) --date=format:%Y --format=%ad)-$(date +%Y)/" LICENSE;git commit -m "Update time for copyright message in license" LICENSE;if [ -n "$stash" ];then git stash pop;fi;git push;done;cd $pwd
    

    自行修改路徑,隨便開個 term 窗口 paste 進去就可以了。 POSIX 兼容。 Tested on OS X Yosemite Version 10.10.5 (14F27).

    效果:

    GitHub Public Activity

    第 1 条附言  ·  2016-01-01 16:11:45 +08:00

    起始年份從 commit log 獲取第一個 commit 的時間,當前年份用的 date 指令,默認的格式為 GitHub 生成的 Copyright (c) %Y Your Name

    9 条回复    2016-01-04 20:26:24 +08:00
    49
        1
    49  
       2016-01-01 15:22:34 +08:00 via Android
    E 娘干的漂亮,我也去给好友的 gayhub 提几个 PRprprpr hhhhhhhhhhhhhhhhh
    kn007
        2
    kn007  
       2016-01-01 15:25:46 +08:00
    漂亮!
    kumakiti
        3
    kumakiti  
       2016-01-01 15:26:03 +08:00
    确实干的漂亮!
    Elethom
        4
    Elethom  
    OP
       2016-01-01 15:42:12 +08:00
    @49
    加油,少年!鑒於半個 V2EX 都把我 block 了你還有很多的機會。
    wbsdty331
        5
    wbsdty331  
       2016-01-01 16:30:19 +08:00
    不升级 El 吗?
    Elethom
        6
    Elethom  
    OP
       2016-01-01 16:57:25 +08:00
    @wbsdty331
    暫時沒升級的需求就沒升級。畢竟不寫代碼了,不需要隨時跟進開發環境的版本。
    Arthur2e5
        7
    Arthur2e5  
       2016-01-04 11:39:55 +08:00
    用 pushd popd 比 cd 回去优雅啦。另外 quoting 。
    Elethom
        8
    Elethom  
    OP
       2016-01-04 11:45:38 +08:00 via iPhone
    @Arthur2e5
    喵 quoting 怎麼啦。
    KexyBiscuit
        9
    KexyBiscuit  
       2016-01-04 20:26:24 +08:00 via Android
    @Elethom 不过是活跃用户的 1/2 ,不哭,摸头
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3157 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:19 · PVG 22:19 · LAX 07:19 · JFK 10:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.