gpt4 book ai didi

git - Git 中的 user.name 是否可以有尾随句点?

转载 作者:IT王子 更新时间:2023-10-29 00:43:23 26 4
gpt4 key购买 nike

下面的Git语句

cd periodtest/
git init
git config user.name "Test."

# verify that user.name is 'Test.'
git config user.name

touch README
git add README
git commit -a -m "period test"

checkout 结果如下

# check user name after commit
git log
And the resulting commit w/out the period was:
commit 9b7e4960fd8129059b5759d1bb937b60241fd70b
Author: Test <email@test.com>
Date: Wed Oct 1 20:28:28 2014 -0700

period test

有没有办法让那段时间保留在用户名中?

最佳答案

此行为已硬编码到 git 中。

编辑:就目前而言,这对于 git 版本 2.25.1(2020 年 2 月 27 日)仍然适用

要在提交期间创建 author 字符串,git 会从字符串的开头和结尾删除 crud(正如 git 所说的那样)。为此,它使用 ident.c 中定义的 strbuf_addstr_without_crud 函数 - see ident.c line 426 version 2.25.1 .

看一下函数头:

/*
* Copy over a string to the destination, but avoid special
* characters ('\n', '<' and '>') and remove crud at the end
*/
static void strbuf_addstr_without_crud(struct strbuf *sb, const char *src)

See ident.c lines 225-262 version 2.25.1 .

Git 通过另一个检查特定字符的函数来确定 crud

static int crud(unsigned char c)
{
return c <= 32 ||
c == '.' ||
c == ',' ||
c == ':' ||
c == ';' ||
c == '<' ||
c == '>' ||
c == '"' ||
c == '\\' ||
c == '\'';
}

See ident.c lines 198-210 version 2.25.1 .

正如您所看到的,一个句点被 git 视为 crud 并将被删除,目前没有您可以设置的标志或选项来避免这种行为。


这意味着您有两个选择。

  1. 您 fork git 并更改 git 创建 author 字符串的方式。

  2. 或者您在尾随句点后附加另一个字符,例如 Zero-width space (通常不会在控制台上正确打印)

或者,您始终可以在 git 邮件列表上提交功能请求,但在这种情况下,我不会抱太大希望。

关于git - Git 中的 user.name 是否可以有尾随句点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26159274/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com