代码之家  ›  专栏  ›  技术社区  ›  l0b0

如何轻松打印默认的Git作者信息?

git
  •  1
  • l0b0  · 技术社区  · 1 年前

    基本上,有没有更简单的等价物 printf '%s <%s>\n' "$(git config --get user.name)" "$(git config --get user.email)" 以获得类似“我的名字< [email protected] >“内置到Git中?

    最终目标是简化 the following Git alias :

    co-author !git commit --amend --message="$(git show --format=%B --no-patch HEAD)" --message="$(printf 'Co-Authored-By: %s <%s>' "$(git config --get user.name)" "$(git config --get user.email)")"
    
    1 回复  |  直到 1 年前
        1
  •  2
  •   ElpieKay    1 年前

    命令可以更短,尽管 printf 部分并没有按照您预期的方式缩短。

    git commit --amend --no-edit --trailer Co-Authored-By="$(git config user.name) <$(git config user.email)>"
    

    如果要编辑提交消息,请删除 --no-edit

        2
  •  -1
  •   Fares    1 年前

    您可以考虑将git-config-global-get-regexp命令与模式一起使用,尽管它不会短得多:

    git config --global --get-regexp 'user\.(name|email)'
    

    这将为您提供如下输出:

    user.name Your Name
    user.email [email protected]