1

我有一个代码库,一些开发人员通过 RDP 工作并使用远程计算机上的 IDE。我想知道是否有办法强制他们在提交更改时输入自己的名字。现在 Git 默认使用我的名字,这非常烦人,因为我不是做出更改的人。

此外,当将某些内容推送到 GitHub 时,它确实会要求输入用户名/密码,但我似乎无法在提交列表中找到该用户信息的任何指示。

**编辑**仅供参考**

我的初衷是在每次运行提交命令时强制用户在共享帐户下登录(不可避免)输入他们的user.name和凭据。user.email为了实现这一点,我尝试使用 Windows 的登录脚本,每次新用户登录时,它基本上都会清除和设置这些值;

@echo off
cls

REM * Notify user
echo Clearing Git user information...

REM * Go to Git directory
cd C:\"Program Files (x86)"\Git\bin\

REM * Clear user information
git config --global --remove-section user

REM * Get the user's name
set /p name= Please enter your first name:

REM * Get user email
set /p email= Please enter your email:

REM * Set Git configuration
git config --global user.name "%name%"
git config --global user.email "%email%"
::REM * exit
exit

但是我无法通过它的主要用例 RDP 让它始终如一地工作。

这导致我尝试使用pre-commitGit 的钩子,我基本上使用了为 Bash 修改的相同脚本。这也不起作用,因为 Git 在调用钩子之前分配了“作者”。

换句话说,如果用户配置是name = jim并且email = bob@test.comGit 日志将作者作为jim<bob@test.com>,那么下一次提交将具有输入的信息。

#!/bin/sh
#
exec < /dev/tty

# Notify user
echo "Clearing Git user information..."

# Go to Git directory
#cd c:\"Program Files (x86)"\Git\bin\

# Clear user information
git config --global --remove-section user

# Get the user's name
echo "Please enter your first name: "
read name

# Get user email
echo "Please enter your email: "
read email

echo name: $name email: $email
read -n 1

# Set Git configuration
git config --global user.email $email
git config --global user.name $name
#exit
4

1 回答 1

3

您看起来处于肮脏的开发设置中,因此有些肮脏:

制作一个删除 Git 的用户名和电子邮件的登录脚本,开发人员每次连接到机器时都必须输入它。

git config --remove-section user

如果未配置,Git 将在第一次运行时询问姓名/电子邮件。

当然,创建 Windows 用户会话并拥有每个用户的 Git 配置会更好:)

于 2012-12-10T15:09:45.927 回答