用户名/邮箱
# 获取用户名称、邮箱
git config user.name
git config user.email
# 获取全局用户名称、邮箱
git config --global user.name
git config --global user.email
# 设置用户名称、邮箱
git config user.name "徐晓伟"
git config user.email "xuxiaowei@xuxiaowei.com.cn"
# 设置全局用户名称、邮箱
git config --global user.name "徐晓伟"
git config --global user.email "xuxiaowei@xuxiaowei.com.cn"
SSL 验证
# 获取证书是否验证
git config http.sslVerify
# 获取全局证书是否验证
git config --global http.sslVerify
# 忽略证书验证
git config http.sslVerify false
# 全局忽略证书验证
git config --global http.sslVerify false
全局排除
# 全局忽略文件夹
git config --global core.excludesfile ~/.gitignore_global
echo "target/" >> ~/.gitignore_global
长路径
# 获取全局是否允许 git 长路径
git config --global core.longpaths
# 全局设置 git 长路径
git config --global core.longpaths true
安全目录
# 获取全局 安全目录
git config --global safe.directory
# 全局设置 安全目录
git config --global safe.directory *
代理
# 查看全局 http GitHub 代理
git config --global http.http://github.com.proxy
# 全局设置 http GitHub 代理
git config --global http.http://github.com.proxy socks5://127.0.0.1:1080
# 取消 全局设置 http GitHub 代理
git config --global --unset http.http://github.com.proxy
# 查看全局 https GitHub 代理
git config --global http.https://github.com.proxy
# 全局设置 https GitHub 代理
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
# 取消 全局设置 https GitHub 代理
git config --global --unset http.https://github.com.proxy
git 子模块
添加子模块
git 子模块 可以将 其他 git 项目 的 某次提交记录 添加到 本项目
git 子模块 的仓库地址会记录在项目的 .gitmodules、.git/config 文件中
git 子模块 的 .git 文件夹放在 .git/modules/子模块文件
git 子模块 的仓库的 某次提交记录 会记录在 添加 git 子模块的文件夹 中
git 子模块 项目示例:
- Kubernetes 文档源码
# git 添加 子模块 帮助文档
git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
# git 添加 子模块 示例
# 将 https://gitee.com/xuxiaowei-com-cn/abcdefg.git 项目的当前 master 分支的最新一次代码提交记录添加到 abcdefg 文件夹
# 其中 域名 可以省略,支持相对路径
git submodule add -b master https://gitee.com/xuxiaowei-com-cn/abcdefg.git abcdefg
删除子模块
- 删除
.gitmodules 文件中对应的子模块信息
- 删除
.git/config 文件中对应的子模块信息
- 删除
.git/modules 文件夹中对应的子模块信息
- 删除
子模块文件夹
克隆带有 git 子模块的项目
# git 克隆带有 子模块 的项目 帮助文档
git clone [--recurse-submodules] [--] <repository> [<directory>]
# git 克隆带有 子模块 的项目 示例
# 递归地克隆子模块
git clone --recurse-submodules https://gitee.com/xuxiaowei-com-cn/xyz.git
# git 手动克隆子模块
# 如果在克隆时,未添加 --recurse-submodules 参数,则手动克隆子模块
git submodule update --init --recursive
# git 手动克隆子模块 仅初始化
git submodule update --init
# git 手动克隆子模块 仅递归
git submodule update --recursive
# git 子模块 循环 检出指定分支
git submodule foreach git checkout <branch>
# git 子模块 循环 拉取最新代码
git submodule foreach git pull
# git 子模块 拉取远端
git submodule update --remote
git 引用日志
# git 引用日志 帮助文档
git reflog
OS
| OS |
git |
正常运行 |
说明 |
| CentOS 7.8.2003 |
2.43.5 |
 |
|
| CentOS 7.8.2003 |
2.44.3 |
 |
yum -y install expat-devel |
| CentOS 7.8.2003 |
2.46.3 |
 |
|