生而为人

程序员的自我修养

0%

工作区、暂存区、版本库

link

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

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

LF will be replaced by CRLF

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

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

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/
1
2
3
4
5
6
140.82.114.4 github.com
151.101.1.6 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
> sudo vi /etc/hosts

Windows:

1
> ipconfig /flushdns

参考资料:

  1. git config doc
  2. Configuring Git to handle line endings

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

本地运行

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 "标题" 命令自动生成带有 titledate 的基础 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 "标题" 都会生成带有这些字段的文件。

主题

  1. One dark vivid Italic(plugins - One Dark theme)