在 Git 的使用过程中,会遇到很多疑问或者奇奇怪怪的问题,在这里挑出几个问题说明下
- Git Bash 不能显示中文
- Git 管理中,文件大小写问题
- Git 中使用 help
- 到底什么是 commitid ?
- 每次都需要输入Git 密码
配置问题
Git Bash 不能显示中文
假设目录里面新增了一个中文名称的 txt, 使用 git status 查看有改动但未提交的文件时总只显示数字串,显示不出中文文件名。
这是因为在 默认设置下,Git 显示为八进制字符编码
解决方案
首先 将 Git 配置文件 core.quotepath 项设置为 false(不会对 0x80 以上的字符进行 quote)
git bash 终端输入命令:git config --global core.quotepath false
quotepath
表示引用路径--global
表示全局配置
这样设置后如果无效,那么 git bash 终端也需要设置成中文和 utf-8 编码。
在 git bash 的界面中右击空白处,弹出菜单,
选择 选项 (Options) -> 文本 (Text),本地 (Local) 设置为zh_CN,字符集选框选为 UTF-8
Git 管理中,文件大小写问题
如果修改了一个文件或目录的大小写,status 查看一下,是看不到更改的
原因是: Git 默认不区分大小写
所以最好把 Git 的大小写敏感开启,否则可能有坑
解决方案
git config --get core.ignorecase
查看默认配置
然后把这项设置成 false 表示区分大小写 git config core.ignorecas false
Git 操作问题
help
Git 命令虽然不难,但有时候容易记混,在基本 Git 关键字后面使用-h
选项可获得相关使用方法
比如 查看 config
都有哪些选项,使用 git config -h
$ git config -h
usage: git config [<options>]
Config file location
--global use global config file
--system use system config file
--local use repository config file
-f, --file <file> use given config file
--blob <blob-id> read config from given blob object
Action
--get get value: name [value-regex]
--get-all get all values: key [value-regex]
--get-regexp get values for regexp: name-regex [value-regex]
--get-urlmatch get value specific for the URL: section[.var] URL
--replace-all replace all matching variables: name value [value_regex]
--add add a new variable: name value
--unset remove a variable: name [value-regex]
--unset-all remove all matches: name [value-regex]
--rename-section rename section: old-name new-name
--remove-section remove a section: name
-l, --list list all
-e, --edit open an editor
--get-color find the color configured: slot [default]
--get-colorbool find the color setting: slot [stdout-is-tty]
Type
-t, --type <> value is given this type
--bool value is "true" or "false"
--int value is decimal number
--bool-or-int value is --bool or --int
--path value is a path (file or directory name)
--expiry-date value is an expiry date
Other
-z, --null terminate values with NUL byte
--name-only show variable names only
--includes respect include directives on lookup
--show-origin show origin of config (file, standard input, blob, command line)
--default <value> with --get, use default value when missing entry
到底什么是 commitid ?
在保存到 Git 之前,所有数据都要进行内容的校验和(checksum)计算,并将此结果作为数据的唯一标识和索引,这也就是我们所说的 commitid。
Git 使用 SHA-1 算法计算数据的校验和,通过对文件的内容或目录的结构计算出一个 SHA-1 哈希值,作为标识字符串。该字符串由40个十六进制字符(0-9 以及 a-f)组成,看起来就是
0782cd519162a6e8c9679b79b61b836fa790d947
所以我们前面提到的 commitid 就是 SHA-1 hash值,反之如果说 Git 中的 SHA 就是 commitid 了, 这个值通过 git log
是可以查看,可视化工具也可查看 SHA
每次操作都需要输入用户名和密码
在~/.gitconfig目录下多出一个文件,用来记录你的密码和帐号
git config --global credential.helper store
再进行一次操作,就可以把用户名密码记录下来啦
入门系列到此收官,希望对阅读者有帮助哦,如果有什么疑问可以进行讨论,共同学习进步
系列文章传送门
Git 入门系列(一)- Git 概念/安装/基本操作/远程推送更新
Git 入门系列(二)- 修改管理 / 撤销操作 / 命令及区间关系
Git 入门系列(三)- 分支(上)创建与切换 / 合并 / 查看 / 删除
Git 入门系列(四)- 分支(下)合并解决冲突 / 远程分支
Git 入门系列(五)- stash 贮藏
Git 入门系列(六)- 标签 tag
Git 入门系列(七)- 可视化 Git 管理工具
Git 入门系列(八) - FAQ
欢迎关注个人公众号,【程序媛春哥的手记】