Hexo消除换行符警告+配置Git代理

Hexo消除换行符警告+配置Git代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Curry@DESKTOP-P743UFE MINGW64 /e/Blog/zhang-curry.github.io
$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.email=804158010@qq.com
user.name=kobe-curry
credential.https://gitee.com.provider=generic

Curry@DESKTOP-P743UFE MINGW64 /e/Blog/zhang-curry.github.io
$ git config --global core.autocrlf false

Curry@DESKTOP-P743UFE MINGW64 /e/Blog/zhang-curry.github.io
$ git config --global core.eol lf

Curry@DESKTOP-P743UFE MINGW64 /e/Blog/zhang-curry.github.io
$ git config --global https.proxy socks5://127.0.0.1:10808

Curry@DESKTOP-P743UFE MINGW64 /e/Blog/zhang-curry.github.io
$ git config --global http.proxy socks5://127.0.0.1:10808

Curry@DESKTOP-P743UFE MINGW64 /e/Blog/zhang-curry.github.io
$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.email=804158010@qq.com
user.name=kobe-curry
credential.https://gitee.com.provider=generic
core.autocrlf=false
core.eol=lf
https.proxy=socks5://127.0.0.1:10808
http.proxy=socks5://127.0.0.1:10808

你现在执行 git config --list 看到的是 Git 全局配置清单,这里面能找到两个关键信息,既解释了为什么换行符警告一直出现,也能看到 Gitee 相关的凭证配置(对应你刚才部署成功的 Gitee 仓库),我帮你逐句解读清楚:

一、先解读配置清单中的核心条目(重点关注和你问题相关的)

  1. core.autocrlf=true(核心:换行符警告的根源)
    • 含义:这是 Git 的全局配置,true 表示开启自动换行符转换(Windows 系统 Git 安装时的默认配置)。
    • 对应你的换行符警告:正因为这个配置是 true,Git 才会在检测到 Hexo 生成的 LF 格式文件时,提示要转换成 CRLF,这就是警告一直出现的根本原因。
    • 补充:这个配置是全局生效的,对所有 Git 仓库都有影响,之前你在 Hexo 目录初始化仓库后配置的本地 core.autocrlf=false,如果没生效,就是被这个全局 true 覆盖了(或本地配置未正确设置)。
  2. credential.https://gitee.com.provider=generic(Gitee 部署成功的凭证配置)
    • 含义:Git 已经记录了 Gitee 仓库的访问凭证配置,这是你刚才部署 Gitee 时输入账号密码后,Git 自动保存的凭证信息。
    • 作用:后续你再执行 hexo d 部署到 Gitee 时,Git 会自动读取这个凭证,无需重复输入账号密码,直接完成部署,这是正常且方便的配置。
  3. 其他默认配置(无需关注,不影响你的使用)
    • diff.astextplain.textconv=astextplain:文本文件对比的默认工具。
    • http.sslbackend=schannel:Windows 系统下 Git 使用的 SSL 后端(默认即可)。
    • user.email=804158010@qq.com / user.name=kobe-curry:你的 Git 全局用户信息(提交代码时的作者信息,正常配置)。
    • init.defaultbranch=master:Git 初始化仓库时的默认分支(对应你的 Hexo 分支,无冲突)。

二、(可选)彻底消除换行符警告(修改全局 / 本地配置,二选一)

如果你还是想消除那个无危害的警告,有两种方式,按需选择:

方式 1:修改 Git 全局配置(所有仓库都生效,一劳永逸)

1
2
3
4
# 关闭全局自动换行符转换,统一使用 LF 换行符
git config --global core.autocrlf false
# 全局强制文件使用 LF 换行符
git config --global core.eol lf

执行后,再执行 git config --list,会看到 core.autocrlf=false,后续所有 Git 仓库都不会再出现换行符转换警告。

方式 2:仅修改 Hexo 仓库本地配置(不影响其他仓库,更灵活)

1
2
3
# 进入 Hexo 根目录(当前已经在该目录,直接执行以下命令)
git config core.autocrlf false
git config core.eol lf

执行后,仅当前 Hexo 仓库不会出现换行符警告,其他 Git 仓库仍使用全局配置,适合需要区分不同仓库格式的场景。

三、总结

  1. 配置清单中 core.autocrlf=true 是换行符警告的根源,也是 Windows Git 的默认配置;
  2. credential.https://gitee.com.provider=generic 是 Gitee 凭证配置,确保后续部署无需重复输入账号密码,是正常配置;
  3. 消除警告可选择修改 Git 全局配置(一劳永逸)或 Hexo 本地配置(灵活区分),均无副作用;
  4. 你的 Gitee 博客部署已成功,后续只需执行 hexo clean && hexo g && hexo d 即可更新博客,无需关注其他配置问题。

至此,你的 Hexo 博客相关配置和部署问题已全部解决,后续可以专注于创作博客内容啦!

配置 Git 代理(让 Git 流量走代理!)

即使开启了系统代理,Git 也可能不会自动复用,需要手动配置 Git 代理,步骤如下:

  1. 打开 Git Bash,执行以下命令(对应代理工具的端口,默认 7890,若你的代理端口是 1080 / 其他,替换即可):

    1
    2
    3
    4
    5
    6
    7
    # 配置 socks5 代理(速度更快,兼容性更好,优先选择)
    git config --global http.proxy socks5://127.0.0.1:7890
    git config --global https.proxy socks5://127.0.0.1:7890

    # 若 socks5 不生效,切换为 http 代理
    # git config --global http.proxy http://127.0.0.1:7890
    # git config --global https.proxy https://127.0.0.1:7890
  2. 验证代理配置是否生效:执行 git config --list,若能看到 http.proxy=socks5://127.0.0.1:7890,说明配置成功。

三、步骤 2:修改 Hexo 配置,同时推送 Gitee 和 GitHub(两全其美)

你可以配置 Hexo 同时部署到 Gitee 和 GitHub,既保留 Gitee 的国内稳定访问,又实现 GitHub 的全球访问,步骤如下:

  1. 打开 Hexo 根目录的 _config.yml找到 deploy 块,修改为以下格式(支持多仓库部署):

    1
    2
    3
    4
    5
    6
    7
    8
    deploy:
    type: git
    repo:
    # 第一个仓库:Gitee(国内访问,已部署成功)
    gitee: https://gitee.com/zhang-curry/ZhangCurry.git
    # 第二个仓库:GitHub(全球访问,替换为你的 GitHub 仓库 HTTPS 地址)
    github: https://github.com/Zhang-Curry/Zhang-Curry.github.io.git
    branch: main
  2. 保存文件(Ctrl+S),确保格式正确(repo 下缩进 2 个空格,gitee/github 后加冒号和空格)。

四、步骤 3:清除 Hexo 缓存,执行完整部署命令

  1. 手动删除 Hexo 根目录下的 db.jsonpublic.deploy_git 文件夹(清除旧缓存,避免冲突)。

  2. 在 Git Bash 中执行完整部署命令:

    1
    hexo clean && hexo g && hexo d
  3. GitHub 身份验证(关键!):

    • 执行后会弹出 GitHub 身份验证提示,用户名输入你的 GitHub 账号(如 Zhang-Curry)
    • 密码输入你的「个人访问令牌」(必须勾选 repo 权限,若丢失,按之前步骤重新生成,生成后务必保存)。

后续注意事项(避坑)

  1. 代理保持开启:每次推送到 GitHub 时,务必确保代理工具已开启且节点可用,否则会再次出现 443 端口超时。

  2. 个人访问令牌保存:GitHub 个人访问令牌仅显示一次,务必保存到记事本中,后续部署无需重新生成。

  3. 换行符警告:依旧可以忽略,不影响 GitHub 部署和博客访问。

  4. 取消代理(可选)

    :若后续不需要访问 GitHub,可执行以下命令取消 Git 代理:

    1
    2
    git config --global --unset http.proxy
    git config --global --unset https.proxy

取消 Git 全局代理

1
2
3
# 取消 Git 全局 http/https 代理
git config --global --unset http.proxy
git config --global --unset https.proxy

为 GitHub 单独配置代理

1
2
3
# 仅为 github.com 配置 socks5 代理(端口 10808,和你的代理工具一致)
git config --global http.https://github.com.proxy socks5://127.0.0.1:10808
git config --global https.https://github.com.proxy socks5://127.0.0.1:10808