你需要改变你的user.name
and user.email
当你承诺的时候。
为了在不影响 git 配置的情况下执行此操作,您可以为特定提交设置环境变量,以便“以其他人的身份”执行该提交。
GIT_AUTHOR_NAME="anotherName" GIT_AUTHOR_EMAIL="another@email" \
GIT_COMMITTER_NAME="anotherName" GIT_COMMITTER_EMAIL="another@email" \
git commit -m "commit done as another person"
这仅适用于当前提交。
所有其他的都将用user.name
and user.email
您看到的值git config --global --list
.
请参阅“环境变量 http://git-scm.com/docs/git#_environment_variables" of git 联机帮助页 http://git-scm.com/docs/git对于您可以设置的所有变量。
另一种方法是使用以下命令覆盖 git 命令上的配置-c
的选项git command http://git-scm.com/docs/git:
git -c user.name="anotherName" -c user.email="another@email" commit -m "..."
(小写'-c
',不是大写'-C
',这是另一种选择)
设置为别名更容易,在 Windows 中称为doskey https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/doskey.mspx?mfr=true:
dokey gituser1=git -c user.name="anotherName" -c user.email="another@email" $*
(the $*
是获取您将传递给该命令的所有其他参数)
您可以将其用作:
gituser1 commit -m "commit done as another person"
我收到一个错误
C:\repo>
GIT_AUTHOR_NAME="Bob" GIT_AUTHOR_EMAIL="[email protected] /cdn-cgi/l/email-protection"
'GIT_AUTHOR_NAME' is not recognized as an internal or external command,
operable program or batch file.
事实上,Windows shell 不会直接支持该语法。
正如《在Windows中只为一个命令设置环境变量cmd.exe https://superuser.com/a/223126“,您需要输入:
cmd /C "set GIT_AUTHOR_NAME=\"anotherName\"
&& set GIT_AUTHOR_EMAIL=\"another@email\"
&& set GIT_COMMITTER_NAME=\"anotherName\"
&& set GIT_COMMITTER_EMAIL=\"another@email\"
&& git commit -m \"commit done as another person\""
(一条巨线)
注意 - 在 windows/cmd 中,您必须删除所有反斜杠和最后一个双引号才能使其工作。