如何告诉git为给定项目使用正确的身份名称和电子邮件?

如何解决如何告诉git为给定项目使用正确的身份名称和电子邮件?

| 我将个人笔记本电脑用于工作和个人项目,我想将工作电子邮件地址用于工作提交(gitolite),将个人电子邮件地址用于其余工作(github)。 我了解了以下所有全局或临时解决方案:
git config --global user.email \"bob@example.com\"
git config user.email \"bob@example.com\"
git commit --author \"Bob <bob@example.com>\"
设置
GIT_AUTHOR_EMAIL
GIT_COMMITTER_EMAIL
EMAIL
环境变量之一 一种解决方案是手动运行将我的环境设置为工作或个性化的shell函数,但是我可以肯定,我经常会忘记切换到正确的身份,从而导致使用错误的身份进行提交。 是否可以将某个存储库,项目名称等绑定到身份(名称,电子邮件)?人们在做什么?     

解决方法

git config user.email \"bob@example.com\"
在存储库中执行该操作将在该存储库(而不是全局)上设置配置。 除非您误读了,否则这似乎就是您所追求的。     ,您需要使用以下本地设置命令: 本地集
git config user.email mahmoud@company.ccc
git config user.name \'Mahmoud Zalt\'
本地获取
git config --get user.email
git config --get user.name
本地配置文件位于项目目录:“ 9”。 全局集
git config --global user.email mahmoud@zalt.me
git config --global user.name \'Mahmoud Zalt\'
全球获得
git config --global --get user.email
git config --global --get user.name
您的主目录中的全局配置文件:
~/.gitconfig
。 切记用空格等引号,例如:\'FirstName LastName \'     ,使用\“。git \”文件夹编辑配置文件,以保持不同的用户名,电子邮件取决于存储库 转到您的存储库 显示隐藏的文件并转到\“。git \”文件夹 找到\“ config \”文件 在EOF处添加以下行   [用户]      名字=鲍勃      电子邮件= bob@example.com 以下命令显示了为此存储库设置的用户名和电子邮件。   git config-获取用户名      git config --get user.email 示例:对于我在D:\\ workspace \\ eclipse \\ ipchat \\。git \\ config中的配置文件 ipchat是我的回购名称     ,如果使用
git config user.email \"foo@example.com\"
,它将绑定到您所在的当前项目。 那就是我为我的项目所做的。克隆/初始化存储库时,我设置了适当的标识。它不是万无一失的(如果您忘记并在发现软管之前先将其推开),但即使没有“ѭ14”的提示,它也可以达到最好的效果。 实际上,您可以设定非法价值。设置your15ѭ 然后,如果您忘记设置非全局值,则会收到错误消息。 [编辑] 在不同的系统上,我必须将x的数量增加到968,以使其失败并显示“致命:个人识别码太长”。相同版本的git。奇怪。     ,如果不使用
--global
参数,它将仅设置当前项目的变量。     ,从Git 2.13开始,您可以在gitconfig中使用ѭ17来根据运行git命令的存储库的路径包括具有不同配置的文件。 自从Ubuntu 18.04附带了足够多的新Git以来,我一直很高兴在
~/.gitconfig
中使用它。
[include]
  path = ~/.gitconfig.alias # I like to keep global aliases separate
  path = ~/.gitconfig.defaultusername # can maybe leave values unset/empty to get warned if a below path didn\'t match
# If using multiple identities can use per path user/email
# The trailing / is VERY important,git won\'t apply the config to subdirectories without it
[includeIf \"gitdir:~/projects/azure/\"]
  path = ~/.gitconfig.azure # user.name and user.email for Azure
[includeIf \"gitdir:~/projects/gitlab/\"]
  path = ~/.gitconfig.gitlab # user.name and user.email for GitLab
[includeIf \"gitdir:~/projects/foss/\"]
  path = ~/.gitconfig.github # user.name and user.email for GitHub
https://motowilliams.com/conditional-includes-for-git-config#disqus_thread 要使用Git 2.13,您将需要添加PPA(早于18.04 / Debian的Ubuntu)或下载二进制文件并进行安装(Windows /其他Linux)。     ,  一种解决方案是手动运行将我的环境设置为工作或个性化的shell函数,但是我可以肯定,我经常会忘记切换到正确的身份,从而导致使用错误的身份进行提交。 那正是我的问题。我编写了一个钩子脚本,如果您有任何github远程并且未定义本地用户名,则会向您发出警告。 设置方法如下: 创建一个目录来保存全局钩子
mkdir -p ~/.git-templates/hooks
运行git init或克隆时,告诉git将
~/.git-templates
中的所有内容复制到每个项目
.git
目录中
git config --global init.templatedir \'~/.git-templates\'
现在将以下行复制到
~/.git-templates/hooks/pre-commit
并使其可执行文件(别忘了这个,否则git不会执行它!)
#!/bin/bash

RED=\'\\033[0;31m\' # red color
NC=\'\\033[0m\' # no color

GITHUB_REMOTE=$(git remote -v | grep github.com)
LOCAL_USERNAME=$(git config --local user.name)

if [ -n \"$GITHUB_REMOTE\" ] && [ -z \"$LOCAL_USERNAME\" ]; then
    printf \"\\n${RED}ATTENTION: At least one Github remote repository is configured,but no local username. \"
    printf \"Please define a local username that matches your Github account.${NC} [pre-commit hook]\\n\\n\"
    exit 1
fi
如果您使用其他主机作为私有存储库,则必须根据需要替换ѭ26。 现在每次执行
git init
git clone
git都会将此脚本复制到存储库并在完成任何提交之前执行它。如果您尚未设置本地用户名,它将输出警告,并且不允许您提交。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-