ssh#
ssh-keygen -t rsa -b 4096 -C "email@example.com"
拉取远程分支#
在本地创建分支 dev 并切换到该分支
git checkout -b dev(本地分支名称) origin/dev(远程分支名称)
将远程分支拉到本地
git fetch origin dev(远端分支名)
创建空分支#
git checkout --orphan empty-branch-name
撤销#
撤销工作区
git checkout filename
撤销暂存区
git reset HEAD filename
撤销 merge(没 git add
时)
git merge --abort
取消文件或文件夹追踪#
# 删除 readme1.txt 的跟踪,并保留在本地git rm --cached readme1.txt# 删除 dir1 目录,并保留在本地git rm -r --cached dir1# 删除 readme1.txt 的跟踪,并且删除本地文件git rm --f readme1.txt
代理#
推送拉取代码失败时,可能是配置的代理有问题,可以取消代理配置试试。
# 检查当前代理配置git config --global --get http.proxygit config --global --get https.proxy# 取消代理git config --global --unset http.proxygit config --global --unset https.proxy
错误#
remote: HTTP Basic: Access denied.#
If a password was provided for Git authentication, the password was incorrect or you’re required to use a token instead of a password. If a token was provided, it was either incorrect, expired, or improperly scoped.
账号密码验证不通过,密码或者权限不对,导致 Git 操作失败。移除令牌,重新登录。
# 移除令牌git config --system --unset credential.helper# 长期存储令牌git config --global credential.helper store# 短期存储令牌,缓存在守护进程的内存git config --global credential.helper cache
fatal: refusing to merge unrelated histories#
git merge master --allow-unrelated-histories# orgit pull --allow-unrelated-histories
git 默认不区分大小写#
因为 git 考虑到兼容,默认不区分文件及文件夹的名称大小写。这个默认配置是分系统的: windows 不区分 macOS 不区分 Linux 区分
通过以下命令试 git 区分大小写
git config core.ignorecase false
https://www.kktoo.com/wiki/gitprofile/Chapter6/ignorecase.html