居家办公的背景下,家里的电脑需要同时支撑自己和公司的项目,根据 GitHub/GitLab 网站的提交记录上看,其是根据邮箱来辨识用户的,所以有必要分别针对不同的项目设置不同的 Git 名字 user.name
和邮箱 user.email
。
以 Git 项目 https://github.com/mazeyqian/mazey 为例:
cd /Users/X/Web/mazey
git config user.name "Your Name"
git config user.email "your@email.com"
验证一下修改结果:
cat .git/config
输出:
...
[user]
email = your@email.com
name = Your Name
然后此项目的提交信息就不再受全局设置的用户名和邮箱影响了。
一键批量修改单个文件夹下所有 Git 项目,免去动手烦恼,批量执行文件下载地址:
https://github.com/mazeyqian/go-gin-gee/releases/tag/v1.0.0
参数 | 说明 |
---|---|
path | 项目文件夹,将批量修改此文件夹下面的所有 Git 项目 |
username |
|
useremail |
|
Example 1: MacOS change-git-user.sh
#!/bin/bash
./change-git-user-mac-darwin-amd64 -path="/Users/X/Web" -username="Your Name" -useremail="your@email.com"
Example 2: Linux change-git-user.sh
#!/bin/bash
chmod u+x ./change-git-user-linux-amd64
./change-git-user-linux-amd64 -path="/Users/X/Web" -username="Your Name" -useremail="your@email.com"
输出:
2022/12/18 14:31:49 Change git user...
2022/12/18 14:31:49 absolutePath: /Users/X/Web
2022/12/18 14:31:49 userName: Your Name
2022/12/18 14:31:49 userEmail: your@email.com
2022/12/18 14:31:49 result: - - begin - -
...
...
- - end - - - - - - - - - - - - - - - - -
All done.
Example 2: Windows CMD
change-git-user-windows-amd64-v5.exe -path="C:\Web" -username="YourName" -useremail="your@email.com"
参考
版权声明
本博客所有的原创文章,作者皆保留版权。转载必须包含本声明,保持本文完整,并以超链接形式注明作者后除和本文原始地址:https://blog.mazey.net/2956.html
(完)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有