git 学习及问题

NOTHING

1.power shell 中 git log 中文显示问题

今天试着使用 power shell 来提交代码,然后使用 git log 查看提交记录的时候,发现无法显示中文,确切地说是中文被显示为对应 ASCII 字符:

add(docs): <E5><A2><9E><E5><8A><A0> linux-<E7><8E><AF><E5><A2><83><E5><8F><98><E9><87><8F><E9><83><A8><E5><88><86><E8><AF><BE><E7><A8><8B><E7><AC><94><E8><AE><B0>

通过查询,阅读 powershell中git log的中文问题PowerShell | git log 中文乱码问题解决 解决了这个问题。

第一步,在 power shell 中输入以下命令:

git config --global core.quotepath false
git config --global gui.encoding utf-8
git config --global i18n.commit.encoding utf-8
git config --global i18n.logoutputencoding utf-8
$env:LESSCHARSET='utf-8'

第二步,添加环境变量:

setx LESSCHARSET 'utf-8'

2.一些小命令

2.1.撤回跟踪

有些时候项目没来得及先建 .gitignore 文件,可能就上传了一些不需要上传的文件,这是需要撤回对这些文件的跟踪,重新提交:

# 针对文件夹,且不删除本地文件的情况
git rm -r --cache document

# 针对文档,且删除本地文件的情况
git rm --f file
  • 处理文件夹时,需要添加 -r;
  • 不想删除本地文件,只是像撤回跟踪,要使用 --cache;

2.2.git 配置

# 查看
git config --global --list

# 添加
git config --global core.autocrlf=false

# 编辑
git config --global --edit

# 删除
git config --global --unset core.autocrlf

# 查看所有的配置以及它们所在的文件
git config --list --show-origin