Skip to content

Git 的使用

· 1 min

拉取远程分支#

在本地创建分支 dev 并切换到该分支

Terminal window
git checkout -b dev(本地分支名称) origin/dev(远程分支名称)

将远程分支拉到本地

Terminal window
git fetch origin dev(远端分支名)

创建空分支#

Terminal window
git checkout --orphan empty-branch-name

撤销#

撤销工作区

Terminal window
git checkout filename

撤销暂存区

Terminal window
git reset HEAD filename

撤销 merge(没 git add 时)

Terminal window
git merge --abort

取消文件或文件夹追踪#

Terminal window
# 删除 readme1.txt 的跟踪,并保留在本地
git rm --cached readme1.txt
# 删除 dir1 目录,并保留在本地
git rm -r --cached dir1
# 删除 readme1.txt 的跟踪,并且删除本地文件
git rm --f readme1.txt

错误#

fatal: refusing to merge unrelated histories#

Terminal window
git merge master --allow-unrelated-histories
# or
git pull --allow-unrelated-histories

git 默认不区分大小写#

因为 git 考虑到兼容,默认不区分文件及文件夹的名称大小写。这个默认配置是分系统的: windows 不区分 macOS 不区分 Linux 区分

通过以下命令试 git 区分大小写

Terminal window
git config core.ignorecase false

https://www.kktoo.com/wiki/gitprofile/Chapter6/ignorecase.html