本文最后更新于 254 天前 ,文中信息可能已经过时。如有问题请在评论区留言。

配置相关

如何修改项目的 git 用户名 / 邮箱

方式一:

修改 .git 文件夹中的 config 文件:

config
1
2
3
[user]
  name = yourname
  email = email@example.com

方式二:

通过命令行执行以下命令修改:

shell
1
2
3
4
5
6
7
8
# 修改当前项目的 git 用户名
git config user.name "yourname"
# 修改当前项目的 git 邮箱
git config user.email "email@example.com"
 
# 或者你也可以修改全局配置
git config --global user.name "yourname"
git config --global user.email "email@example.com"

禁用 SSL 校验

执行以下命令禁用 SSL 校验。

shell
1
git config --global http.sslVerify false

功能相关

修改 .gitignore 文件后使其生效

思路:清除全局缓存后再添加所有文件

shell
1
2
3
4
5
6
# 1. 清除缓存 (别忘了 ".")
git rm -r --cached .
# 2. 添加所有文件 (别忘了 ".")
git add .
# 3. 提交 [可选]
git commit -m "update .gitingore"

生成密钥

执行以下命令生成密钥:

shell
1
ssh-keygen -t ed25519 -C "email@example.com"

更新远程分支列表

执行以下命令更新远程分支列表:

shell
1
git remote update origin --prune

必须带 --prune ,否则效果和 git fetch 一样,即新增加的分支能 fetch 下来,但是被删掉的分支却不能同步删掉本地的 origin 的。

修改远程仓库地址后提示 401

错误描述:

text
1
error: RPC failed; HTTP 401 curl 22 The requested URL returned error: 401

解决方式:

shell
1
git remote set-url origin <new-url>

然后重新 push 就会提示输入账号 / 密码。

修改提交时间

使用如下代码,可以提交到指定的时间:

shell
1
git commit --date="Sep 30 15:05:20 2022 +0800" -am "提交内容"

月份可参考 附录:月份对照表

附录

月份对照表

月份英文缩写
1 月JanuaryJan
2 月FebruaryFeb
3 月MarchMar
4 月AprilApr
5 月MayMay
6 月JuneJun
7 月JulyJul
8 月AugustAug
9 月SeptemberSep
10 月OctoberOct
11 月NovemberNov
12 月DecemberDec