Git在提交时指定用户和电子邮件吗? [英] Git specify user and e-mail on commit?

查看:481
本文介绍了Git在提交时指定用户和电子邮件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经在测试服务器上创建了代码的分支,多个用户现在正在通过SSH进入新服务器并使用命令行进行所有提交来进行工作.但是,当然,Git不知道由谁进行更改并将其提交,因此我们需要在提交期间指定作者.

We have created a branch of our code on a testing server which multiple users are now working on by SSH'ing into the new server and doing all the committing with the command line. BUT, of course Git doesn't know whose making the changes and committing them, so we need to specify the author during the commit.

我认为我们可以通过以下方式实现这一目标:

I thought we could achieve this with:

git commit -a -m 'removed temporary images' --author='deed02392 <foo@bar.net>'

但这给出了:

[test-branch 77b9357] removed temporary image 
    Author: deed02392 <foo@bar.net>
    Committer: root <root@vs123.(none)>
    Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author='Your Name <you@example.com>'

 1 files changed, 0 insertions(+), 0 deletions(-)  delete mode 100644 derp.PNG

期望每个用户每次都更改配置似乎太过分了.这是因为Git并非旨在让多个用户使用一个存储库而造成的?

It seems too much to expect every user to change the config every time. Is this behaviour because Git is not designed to let multiple users play with one repository?

推荐答案

想法1:看看此链接,其中显示了如何使用环境变量来定义作者姓名等.

想法2: 例如,Github有一个通用的"git"用户,每个人都使用它来将更改推送到他们的存储库,并且他们可以通过ssh密钥(除其他外)来区分用户.您可以朝这个方向尝试一些方法,尽管由于您是直接在服务器上工作,所以我不确定它是否可以用于您的设置.

Idea2: Github for example has a generic 'git' user that's used by everyone to push changes to their repositories, and they distinguish users by, possibly amongst others, ssh keys. You could try something in that direction, though I'm not sure if it will work for your setting, as you're working directly on the server.

这些链接是相关的:此链接.这是一个链接,说明 gitolite如何实现ssh魔术

These links are related: this link, this one. Here's a link explaining how gitolite does the ssh magic

这篇关于Git在提交时指定用户和电子邮件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆