在本地系统上模拟多个用户/提交者 [英] Simulate multiple users/committer's on local system
问题描述
在我的书中,我试图学习如何在本地系统上模拟多个git用户。我
将假装为所有这些多个用户。我遵循我的书的说明来模拟多个用户对repo进行更改。当 git log
是
执行时,图书输出显示了两个不同的人。但是,我的输出只显示一个用户,那就是我。如何让更多用户使我的
可以模拟该场景?
提交aed341198f614860bfb68f5fd5845f191773fa36
作者:sid smith< bob.smith@aol.com>
日期:日期
在更改第一行之后,Bobs首先提交
commit edabfcc8a432b07f92a564147ee6ebb8865f5d18
作者:sid smith< sid.smith@aol.com> ;
日期:日期
源中的基本提交
编辑 - 有没有一个基于网络的git,我可以通过多个浏览器登录(作为多个用户)来模拟git中的多个提交?
您需要更改 user.name
和 user.email
。
要做到这一点而不会影响你的git配置,你可以为特定的提交设置环境变量
GIT_AUTHOR_NAME =其他名称GIT_AUTHOR_EMAIL =另一个@电子邮件\
GIT_COMMITTER_NAME =anotherNameGIT_COMMITTER_EMAIL =another @ email\
git commit -m以另一个人的身份完成
只适用于当前的提交。
所有其他的将使用 user.name
和 user.email
您在中看到的值> git config --global --list
。
请参阅环境变量一节 git ma你可以设置所有的变量。
另一种方法是使用 -c
选项的 git
命令:
git -c user.name =anotherName-c user.email =another @ email提交-m...
<小写字母' -c
',不是大写' -C
',这是另一种选择)
设置为别名,在Windows中称为 doskey
:
dokey gituser1 = git -c user.name =anotherName-c user.email =another @ email$ *
( $ *
将获得所有其他参数)
你会如:
gituser1提交-m作为另一个人完成提交
我收到错误
C:\repo>
GIT_AUTHOR_NAME =BobGIT_AUTHOR_EMAIL =bob.smith444.bob@aol.com
'GIT_AUTHOR_NAME'不被识别为内部或外部命令,
可操作程序或批处理文件。
确实,Windows shell不会直接支持该语法。
正如在为Windows中的一个命令设置环境变量 cmd.exe
,您需要输入:
cmd / Cset GIT_AUTHOR_NAME = \anotherName \
$ p注意 - 在windows / cmd中,你必须删除所有的反斜杠。$ p
&&&& set GIT_AUTHOR_EMAIL = \another @ email\
&&&&&set GIT_COMMITTER_NAME = \anotherName\
&&&&&&&& GIT_COMMITTER_EMAIL = \another @ email \
&&& git commit -m \commit as another person \
(一条巨型线)和最后一个双引号使这项工作。
From my book, I am trying to learn how to simulate multiple git users on my local system itself. I will pretend to be all those multiple users. I followed my book's instructions to simulate multiple users committing changes to a repo. The book output shows two different people when
git log
is executed. But, my output shows only one user, that is me. How do I make more users so that I can simulate the scenario ?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
Edit - Is there a web-based git where I can login (as multiple users) through multiple browsers to simulate multiple commits in git ?
解决方案You need to change your
user.name
anduser.email
when you commit.To do so without affecting your git config, you can set environment variables for a specific commits in order to do that commit "as someone else".
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"
That will apply only for the current commit.
All the others will be done with theuser.name
anduser.email
values you see ingit config --global --list
.See the section "Environment Variables" of the git manpage for all the variable you can set.
Another way is to override the config on the git command with the
-c
option of thegit
command:git -c user.name="anotherName" -c user.email="another@email" commit -m "..."
(lowercase '
-c
', not uppercase '-C
', which is another option)That is easier to set as an alias, which in Windows is called
doskey
:dokey gituser1=git -c user.name="anotherName" -c user.email="another@email" $*
(the
$*
is to get all the othe parameters you will pass to that command)You would use that as:
gituser1 commit -m "commit done as another person"
I get an error
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.
Indeed, Windows shell wouldn't support that syntax directly.
As mentioned in "Setting environment variable for just one command in Windows
cmd.exe
", you would need to type: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\""
(one giant line)
NOTE - In windows/cmd, you must remove all the backslashes and the last double quote to make this work.
这篇关于在本地系统上模拟多个用户/提交者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!