git 设置及其他
包含config、.gitignore、alias
设置
git config edit [--global|--local|--worktree] 打开设置文件以编辑
--global用户全局--local此仓库(默认)--worktree此工作树
…
亦可使用.gitconfig文件设置
Windows 下大小写不分的问题
通过设置:
1 | git config core.ignorecase false |
或者临时:
1 | git mv |
Windows 下路径长度问题
1 | git config --system core.longpaths true |
拉取新分支的问题
有时新分支无法被pull时可以通过检查:
git config --get remote.origin.fetch
得知是否仅追踪了一个分支(如:+refs/heads/master:refs/remotes/origin/master)
如果是,则可以:
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
再 pull 就可以了
代理
git 不仅可以设置代理,还可以进行简单的路由
1 | [http] |
.gitignore
基本只要将文件名、路径遵循相应格式写进.gitignore文件即可,在子目录中也有效
.gitkeep
git 没有办法追踪空文件夹,用户们便使用 .gitkeep 文件占位,并非官方行为
在暂存区声明删除文件
想将文件从版本库中删除,但又不想真的让它消失在自己的硬盘里
1 | git rm --cached <path> |
对比两个文件差异
1 | git diff --no-index [--] <path> <path> |
查看操作历史
会显示形如 HEAD@{1},master@{one.week.ago} 的标记代表曾经它们的位置,可用于 git reset
1 | git reflog |
本地操练
本地通过 git init --bare 可创建一个类似 Github 的仓库,可以被 clone
将子目录分离成独立仓库
(https://docs.github.com/en/get-started/using-git/splitting-a-subfolder-out-into-a-new-repository)
防止误推送
野路子
1 | git remote set-url --push origin "" |
--push指定修改推送 url ,而非拉取 url