模拟本地系统上的多个用户/提交者

时间:2014-06-07 05:53:55

标签: git

从我的书中,我正在尝试学习如何在本地系统上模拟多个git用户。一世 将假装成为所有这些多个用户。我按照我的书的说明模拟了多个用户对repo进行更改。书籍输出显示了git log时的两个不同的人 执行。但是,我的输出只显示了一个用户,就是我。如何让更多用户成为我 可以模拟场景吗?

commit aed341198f614860bfb68f5fd5845f191773fa36
Author: sid smith <bob.smith@aol.com>
Date:   date

    Bobs first commit after changing the first line

commit edabfcc8a432b07f92a564147ee6ebb8865f5d18
Author: sid smith <sid.smith@aol.com>
Date:   date

    Base commit from source

编辑 - 是否有基于网络的git,我可以通过多个浏览器登录(作为多个用户)来模拟git中的多个提交?

1 个答案:

答案 0 :(得分:2)

您提交时需要更改user.nameuser.email

为了在不影响你的git配置的情况下这样做,你可以为特定的提交设置环境变量,以便像其他人那样提交#34;。

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中看到的user.emailgit config --global --list值完成。

请参阅&#34; Environment Variables&#34;对于您可以设置的所有变量,the git manpage

另一种方法是使用git command-c选项覆盖git命令上的配置:

git -c user.name="anotherName" -c user.email="another@email" commit -m "..."

(小写&#39; -c&#39;,不是大写&#39; -C&#39;,这是另一种选择)

这更容易设置为别名,在Windows中称为 doskey

dokey gituser1=git -c user.name="anotherName" -c user.email="another@email" $*

$*将获取您将传递给该命令的所有其他参数)

您可以将其用作:

gituser1 commit -m "commit done as another person"

我收到错误

C:\repo>
GIT_AUTHOR_NAME="Bob" GIT_AUTHOR_EMAIL="bob.smith444.bob@aol.com" 
  'GIT_AUTHOR_NAME' is not recognized as an internal or external command, 
  operable program or batch file.

实际上,Windows shell不会直接支持该语法。

如&#34; Setting environment variable for just one command in Windows cmd.exe&#34;中所述,您需要输入:

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中,您必须删除所有反斜杠和最后一个双引号才能使其正常工作。