生而为人

程序员的自我修养

0%

工作区、暂存区、版本库

link

  • **工作区:**就是你在电脑里能看到的目录。
  • **暂存区:**英文叫 stage 或 index。一般存放在 .git 目录下的 index 文件(.git/index)中,所以我们把暂存区有时也叫作索引(index)。
  • **版本库:**工作区有一个隐藏目录 .git,这个不算工作区,而是 Git 的版本库。

正常编写是在工作区,git add 之后提交到暂存区,git commit之后放到版本库

每次与origin分支对比前,先执行git pull操作,才能获取到远端的最新代码。

[toc]

网络问题

github 网址访问不了

GitHub打不开的解决方案(超简单)

  1. https://sites.ipaddress.com/github.com/
  2. https://sites.ipaddress.com/fastly.net/
  3. https://sites.ipaddress.com/assets-cdn.github.com/

My IP | IP Address Tools | IP Geolocation | Website Traffic Checker

1
2
3
4
5
6
7
8
9
140.82.114.4 github.com
151.101.1.194 github.global.ssl.fastly.net
151.101.65.194 github.global.ssl.fastly.net
151.101.129.194 github.global.ssl.fastly.net
151.101.193.194 github.global.ssl.fastly.net
185.199.108.153 assets-cdn.github.com
185.199.109.153 assets-cdn.github.com
185.199.110.153 assets-cdn.github.com
185.199.111.153 assets-cdn.github.com

Mac:

1
2
3
4
sudo vi /etc/hosts

# 刷新DNS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Windows:

1
> ipconfig /flushdns

配置问题

权限问题

The RSA host key for github.com has changed

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
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for github.com has changed,
and the key for the corresponding IP address 20.205.243.166
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s.
Please contact your system administrator.
Add correct host key in /Users/cjq/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/cjq/.ssh/known_hosts:10
RSA host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
1
2
3
>> ssh-keygen -R github.com			//更新know_hosts中的内容
>> 更新publickey(参考)
>> ssh -T git@github.com // 测试是否能正确连接

问题

LF will be replaced by CRLF

1
2
3
4
git config core.autocrlf false
1. true:
2. false:
3. input:

切换分支时 如何保证文件完全与线上一致,即其他分支新加的文件被删掉

命令报错

Author identity unknown

报错信息

1
2
3
4
5
6
7
8
9
10
11
12
13
Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'jingqi@DESKTOP-BKUPVT9.(none)')

解决办法

  1. 按照指导重新设置user.email和user.name,注意变量名称不要设置错了
  2. 用git var GIT_AUTHOR_IDENT 验证是否设置成功。

参考资料:

  1. git config doc
  2. Configuring Git to handle line endings
  3. https://blog.csdn.net/helloasimo/article/details/123778112

本地运行

1
hexo generate
1
hexo server

服务器部署

1
2
3
hexo clean
hexo d -g
hexo deploy

源码提交

1
2
3
4
git checkout -b blog-source
git add -A
git commit -m "init blog"
git push origin blog-source

参考资料

如何用 Github 搭建博客

bad indentation of a mapping entry

  1. title中缩进不正常,均要用tab缩进

warning: adding embedded git repository: themes/next

1
2
3
4
5
6
7
8
9
10
11
12
13
14
warning: adding embedded git repository: themes/next
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> themes/next
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached themes/next
hint:
hint: See "git help submodule" for more information.

git仓库包含子仓库时,add报错的解决办法

参考资料

hexo部署成功仍未更新或无法打开的情况

修改scheme后发布不起作用

Hexo博客 Next更换修改主题样式 不生效的解决

[toc]

给我一个Front-matter例子

这里是一个包含了常用字段的 Hexo Front-matter 示例,可以直接复制使用:

yaml

复制下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
---
title: 使用Hexo搭建个人博客的完整指南
date: 2026-04-24 10:30:00
updated: 2026-04-25 15:20:00
tags:
- Hexo
- GitHub Pages
- 教程
categories:
- [技术, 前端, 静态博客]
- [工具]
keywords: Hexo,博客搭建,教程
description: 这是一篇详细介绍如何使用Hexo和GitHub Pages搭建个人博客的文章,包含完整的配置步骤和常见问题解答。
author: 你的名字
layout: post
comments: true
toc: true
---

📌 各项字段说明

字段 是否必需 作用
title ✅ 必需 文章标题,会在页面上显示
date ✅ 必需 文章创建时间,影响排序和归档
updated ❌ 可选 文章最后修改时间,SEO友好
tags ❌ 可选 文章标签(可以是列表或单值)
categories ❌ 可选 文章分类,支持多级层级(写法如示例所示)
keywords ❌ 可选 用于SEO的页面关键词
description ❌ 可选 页面描述,在搜索引擎结果中展示
author ❌ 可选 作者名(若主题支持多作者时可使用)
layout ❌ 可选 指定布局模板,默认post
comments ❌ 可选 是否开启评论(需主题支持)
toc ❌ 可选 是否显示目录(需主题支持)

💡 关于 categories 多级写法的补充说明

如果你希望一篇文章同时属于 两个不同的分类体系(例如既属于“日常/游记”,又属于“创作/散文”),可以这样写:

yaml

复制下载

1
2
3
categories:
- [日常, 游记] # 父级“日常”,子级“游记”
- [创作, 散文] # 另一个独立的分类路径

Hexo 会自动为这两个分类路径分别生成页面,文章会出现在两个分类页面中。

如果你希望一个分类下有两级(只有一条路径),也可以简写为:

yaml

复制下载

1
2
3
categories:
- 技术
- 后端

但这会被解析为两个同级分类,而不是层级关系。要表示层级,必须用数组嵌套:- [技术, 后端]。

⚙️ 快速生成 Front-matter

可以使用 hexo new "标题" 命令自动生成带有 title 和 date 的基础 Front-matter;如需更多字段,建议使用 VS Code 的 Hexo Front-matter 等插件,或自己复制模板文件到 scaffolds/post.md 中。

例如,修改 scaffolds/post.md 为你想要的模板:

yaml

复制下载

1
2
3
4
5
6
7
8
9
---
title: {{ title }}
date: {{ date }}
updated:
tags:
categories:
description:
toc: true
---

这样之后每次 hexo new "标题" 都会生成带有这些字段的文件。