Git使用-中文乱码及日志解析

发布时间 2023-10-22 10:46:22作者: Tomato-In

1. 中文乱码

问题描述:使用Git时中文显示乱码

系统信息:Ubuntu22.04

Git版本:2.34.1

乱码现象:

$ git ls-files
"\346\211\223\346\200\252\345\214\205.md"

$ git status
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	Mainwork.md
	"PX4\344\273\243\347\240\201\351\230\205\350\257\273\346\217\220\347\244\272\344\273\245\345\217\212\344\270\273\350\246\201\345\267\245\344\275\234.docx"
	"\344\274\230\350\264\235\347\211\271\347\224\265\346\261\240-CAN\351\200\232\350\256\257\345\215\217\350\256\256\345\256\232\344\271\211.docx"
	"\350\275\257\344\273\266\346\235\277\351\200\232\347\224\250\345\215\217\350\256\256 V4.pdf"

nothing added to commit but untracked files present (use "git add" to track)

原因分析:编码不一致

解决方案:

git config --global core.quotepath false
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8

解决效果:

$ git ls-files
打怪包.md

$ git status
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	Mainwork.md
	PX4代码阅读提示以及主要工作.docx
	优贝特电池-CAN通讯协议定义.docx
	软件板通用协议 V4.pdf

nothing added to commit but untracked files present (use "git add" to track)

2. log解析

$ git log
commit 6881d111a4eac8456c409e018f5fa8d401bdf803 (HEAD -> main, origin/main)
Author: Tomato-in <2544716393@qq.com>
Date:   Sun Oct 22 10:09:44 2023 +0800

    mainwork

commit 57f8c9d19e256ed5f108ac1e8b99235c2e3739b2
Author: Tomato-in <2544716393@qq.com>
Date:   Sun Oct 22 09:20:42 2023 +0800

    Industry knowledge
  • 6881d111a4eac8456c409e018f5fa8d401bdf803:commit id;
  • (HEAD -> main, origin/main)
    • HEAD指针 - 默认指向当前分支所在的最新提交;
    • main分支 - 本地的主分支。该提交也存在于main分支上,表示它属于本地main分支的历史;
    • origin/main - 远程跟踪分支,跟踪origin仓库的main分支。该提交也存在于origin/main上,表示它已经被推送到了origin仓库的main分支。
  • mainwork\Industry knowledge:提交时附带的信息。