更新Git笔记和本地忽略文件

This commit is contained in:
2026-06-23 17:45:55 +08:00
parent 5b0f8b9cde
commit b8bbd7d49e
24 changed files with 252 additions and 361 deletions
+4 -2
View File
@@ -1,8 +1,10 @@
# Obsidian local state
.obsidian/workspace.json
.obsidian/cache/
/.obsidian/workspace*.json
/.obsidian/cache/
/.vs/
/密码本/
/服务器迁移/
/Ignore/
# OS files
-242
View File
@@ -1,242 +0,0 @@
{
"main": {
"id": "a693de761d542948",
"type": "split",
"children": [
{
"id": "de35c53ad452014d",
"type": "tabs",
"children": [
{
"id": "e7c250592202ef1d",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "待办/Unity重学.md",
"mode": "source",
"source": false
},
"icon": "lucide-file",
"title": "Unity重学"
}
}
]
}
],
"direction": "vertical"
},
"left": {
"id": "630f8165e6a24a86",
"type": "split",
"children": [
{
"id": "f0756957054a6fce",
"type": "tabs",
"dimension": 79.77755308392315,
"children": [
{
"id": "ebc68222154201be",
"type": "leaf",
"state": {
"type": "file-explorer",
"state": {
"sortOrder": "byModifiedTime",
"autoReveal": false
},
"icon": "lucide-folder-closed",
"title": "文件列表"
}
},
{
"id": "991397493df067e8",
"type": "leaf",
"state": {
"type": "bookmarks",
"state": {},
"icon": "lucide-bookmark",
"title": "书签"
}
},
{
"id": "cc621346ccdf86c9",
"type": "leaf",
"state": {
"type": "outline",
"state": {
"file": "笔记/Unity笔记汇总.md",
"followCursor": false,
"showSearch": false,
"searchQuery": ""
},
"icon": "lucide-list",
"title": "Unity笔记汇总 的大纲"
}
}
]
},
{
"id": "f8fdc77a59b98c85",
"type": "tabs",
"dimension": 20.222446916076844,
"children": [
{
"id": "ecccd9af8286ea29",
"type": "leaf",
"state": {
"type": "search",
"state": {
"query": "[\"tags\"]",
"matchingCase": false,
"explainSearch": false,
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical"
},
"icon": "lucide-search",
"title": "搜索"
}
}
]
}
],
"direction": "horizontal",
"width": 300
},
"right": {
"id": "c7920e2ce907397e",
"type": "split",
"children": [
{
"id": "a5f3c68213ee3916",
"type": "tabs",
"children": [
{
"id": "42aa94a29399c26f",
"type": "leaf",
"state": {
"type": "backlink",
"state": {
"file": "笔记/Unity笔记汇总.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
"showSearch": false,
"searchQuery": "",
"backlinkCollapsed": false,
"unlinkedCollapsed": true
},
"icon": "links-coming-in",
"title": "Unity笔记汇总 的反向链接列表"
}
},
{
"id": "d651b27dcd912ace",
"type": "leaf",
"state": {
"type": "outgoing-link",
"state": {
"file": "笔记/CSharp/核心/索引器.md",
"linksCollapsed": false,
"unlinkedCollapsed": false
},
"icon": "links-going-out",
"title": "索引器 的出链列表"
}
},
{
"id": "b395181a320df62d",
"type": "leaf",
"state": {
"type": "tag",
"state": {
"sortOrder": "frequency",
"useHierarchy": true,
"showSearch": false,
"searchQuery": ""
},
"icon": "lucide-tags",
"title": "标签"
}
},
{
"id": "d9c193444d1f152f",
"type": "leaf",
"state": {
"type": "all-properties",
"state": {
"sortOrder": "frequency",
"showSearch": false,
"searchQuery": ""
},
"icon": "lucide-archive",
"title": "添加笔记属性"
}
}
],
"currentTab": 3
}
],
"direction": "horizontal",
"width": 200
},
"left-ribbon": {
"hiddenItems": {
"switcher:打开快速切换": false,
"graph:查看关系图谱": false,
"canvas:新建白板": false,
"daily-notes:打开/创建今天的日记": false,
"templates:插入模板": false,
"command-palette:打开命令面板": false,
"bases:新建数据库": false
}
},
"active": "e7c250592202ef1d",
"lastOpenFiles": [
"笔记/CSharp笔记汇总.md",
"待办/Unity重学.md",
"待办/CSharp重学.md",
"笔记/CSharp/进阶/Hashtable.md",
"笔记/CSharp/进阶/Stack.md",
"简历_综合应届生版.md",
"简历_网络运维技术支持方向.md",
"服务器迁移/网站容器迁移与SSL续签手册.md",
"简历_Unity游戏开发方向.md",
"密码本/Teamspeak Recovery Key.md",
"Teamspeak/网站容器迁移与SSL续签手册.md",
"笔记/CSharp/基础/值类型和引用类型.md",
"笔记/CSharp/入门/字符串拼接.md",
"待办/大待办.md",
"未命名.md",
"未命名 1.md",
"服务器迁移",
"笔记/CSharp/进阶/Queue.md",
"笔记/CSharp/进阶/ArrayList.md",
"笔记/Unity笔记汇总.md",
"笔记/CSharp/练习/CSharp综合练习-02.md",
"笔记/CSharp/进阶",
"笔记/CSharp/核心/索引器.md",
"笔记/CSharp/核心/接口.md",
"笔记/CSharp/基础/枚举.md",
"笔记/CSharp/核心/抽象类和抽象方法.md",
"笔记/CSharp/核心/密封函数.md",
"笔记/CSharp/核心/密封类.md",
"未命名.base",
"未命名.canvas",
"密码本",
"图库/CSharp/Pasted image 20260412210327.png",
"笔记/CSharp/练习",
"图库/CSharp/Pasted image 20260412210704.png",
"图库/CSharp/Pasted image 20260412210810.png",
"图库/CSharp/Pasted image 20260412210946.png",
"笔记/CSharp/杂记",
"Pasted image 20260412210946.png",
"Pasted image 20260412210810.png",
"Pasted image 20260412210704.png",
"图库/CSharp/Pasted image 20260412210516.png",
"图库/CSharp",
"图库",
"笔记/CSharp/核心",
"笔记/CSharp/基础"
]
}
Binary file not shown.
@@ -1,31 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "E:\\Obsidian\\OneDrive\\Apps\\remotely-save\\MyNotes\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": -1,
"Children": [
{
"$type": "Bookmark",
"Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:129:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}"
}
]
}
]
}
]
}
-27
View File
@@ -1,27 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "E:\\Obsidian\\OneDrive\\Apps\\remotely-save\\MyNotes\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": -1,
"Children": [
{
"$type": "Bookmark",
"Name": "ST:129:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}"
}
]
}
]
}
]
}
Binary file not shown.
@@ -1,12 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\Kister\\OneDrive\\Apps\\remotely-save\\MyNotes\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
-12
View File
@@ -1,12 +0,0 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\Kister\\OneDrive\\Apps\\remotely-save\\MyNotes\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
-3
View File
@@ -1,3 +0,0 @@
{
"CurrentProjectSetting": null
}
-6
View File
@@ -1,6 +0,0 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
BIN
View File
Binary file not shown.
+22 -4
View File
@@ -5,7 +5,7 @@
当前笔记库路径:
```text
E:\Obsidian\OneDrive\Apps\remotely-save\MyNotes
%USERPROFILE%\OneDrive\Apps\remotely-save\MyNotes
```
GitHub 远程仓库:
@@ -22,13 +22,13 @@ https://github.com/Ki5ter/Obsidian.git
推荐设置成类似:
```text
E:\GitRepos
%USERPROFILE%\GitRepos
```
不推荐设置成:
```text
E:\Obsidian\OneDrive\Apps\remotely-save\MyNotes
%USERPROFILE%\OneDrive\Apps\remotely-save\MyNotes
```
原因是 `MyNotes` 本身就是一个仓库,不应该再作为所有新仓库的默认存放目录。
@@ -52,7 +52,7 @@ URL: https://github.com/Ki5ter/Obsidian.git
1. 在资源管理器中找到笔记库文件夹:
```text
E:\Obsidian\OneDrive\Apps\remotely-save\MyNotes
%USERPROFILE%\OneDrive\Apps\remotely-save\MyNotes
```
2. 如果笔记库在 OneDrive 里,先右键文件夹,选择:
@@ -125,6 +125,24 @@ git -C "E:\Obsidian\OneDrive\Apps\remotely-save\MyNotes" branch -M main
git -C "E:\Obsidian\OneDrive\Apps\remotely-save\MyNotes" push -u origin main
```
## 不建议提交 .vs 目录
Visual Studio 会在仓库里生成 `.vs/` 目录,用来保存本机缓存、索引、窗口布局等内容。
这些文件通常只和当前电脑有关,不适合推送到 GitHub。建议在 `.gitignore` 中加入:
```gitignore
/.vs/
```
如果 `.vs/` 已经被 Git 跟踪过,需要取消跟踪但保留本地文件:
```powershell
git rm --cached -r -- ".vs"
git commit -m "Stop tracking Visual Studio local files"
git push
```
## Clash Verge 代理问题
如果推送时报错:
+114 -22
View File
@@ -1,29 +1,121 @@
初始化:
- git init
# Git 命令速查
添加远程仓库:
- git remote add 远端仓库名 地址
## 初始化和远端
把修改加入暂存区
- git add .
初始化本地仓库
提交修改
- git commit -m "备注信息"
```powershell
git init
```
推送到远程仓库
- git push
- git push -u 远端仓库 本地分支
强推修改
- git push --force-with-lease 远端仓库 本地分支
- --force-with-lease表示先检查有没有比目前分支更新的提交,如果有推送终止,更安全
- --force表示强制修改分远端仓库支指针
添加远端仓库
移除cache中的某个文件更改:
- git rm --cached -r -- "文件目录或文件名"
```powershell
git remote add origin https://github.com/Ki5ter/Obsidian.git
```
移除整个树种的某个文件夹:
- git filter-repo --path "文件名或文件目录" --invert-paths
- git filter-repo --path "多个" --path "多个" --invert-paths
查看远端仓库:
检查远端仓库信息
- git remote -v
```powershell
git remote -v
```
`origin` 是本地给远端仓库地址起的别名,也可以叫 `backup``gitee` 等。
## 日常提交
查看状态:
```powershell
git status
git status --short
```
加入暂存区:
```powershell
git add .
```
提交到本地仓库:
```powershell
git commit -m "提交说明"
```
第一次推送并绑定上游:
```powershell
git push -u origin master
```
绑定后日常推送:
```powershell
git push
```
## 分支和上游
查看当前分支和上游关系:
```powershell
git branch -vv
```
`master``main` 是分支名。`git push origin master` 表示把本地 `master` 分支推送到 `origin` 这个远端。
`-u` 会把本地分支和远端分支绑定起来。绑定后,Git 知道当前分支默认推送到哪里。
## .gitignore 和取消跟踪
`.gitignore` 只会阻止未被跟踪的新文件进入 Git。已经被 Git 跟踪的文件,需要先从索引中移除。
只取消 Git 跟踪,保留本地文件:
```powershell
git rm --cached -r -- "目录或文件名"
git commit -m "Stop tracking local-only files"
git push
```
`--cached` 指 Git 索引/暂存区,不是普通缓存。它不会删除本地实际文件。
## 清理历史中的敏感文件
如果密码、密钥、Token 已经提交过,只从最新提交删除还不够,历史里仍然能看到。应先更换或吊销泄露过的密钥,再重写历史。
删除整个历史中的指定目录:
```powershell
git filter-repo --path "密码本/" --path "服务器迁移/" --invert-paths
```
如果不是 fresh clone,工具可能要求确认:
```powershell
git filter-repo --force --path "密码本/" --path "服务器迁移/" --invert-paths
```
`--path` 指定要匹配的路径;`--invert-paths` 表示反转选择,保留其他路径,删除这些指定路径。
`git filter-repo` 执行后可能会删除 `origin`,需要重新添加:
```powershell
git remote add origin https://github.com/Ki5ter/Obsidian.git
```
历史重写后强推远端:
```powershell
git fetch origin
git push --force-with-lease origin master
```
`--force-with-lease` 会先确认远端分支还停在本地记录的位置,避免覆盖别人新推送的提交。
检查历史里是否还存在指定目录:
```powershell
git log --all -- "密码本/" "服务器迁移/"
```
+112
View File
@@ -42,6 +42,9 @@ https://github.com/Ki5ter/Obsidian.git
`fetch 获取`
只下载远程仓库信息,不自动合并。
`origin/master`
本地记录的远端 `origin``master` 分支的位置。它不是远端本身,而是本地上次获取到的远端状态。
## 基本工作流程
1. 打开工作区,也就是要纳入版本控制的文件夹。
@@ -94,6 +97,36 @@ git push
git pull
```
## origin、master 和 push
`origin` 是远端仓库地址的别名。它保存在本地 Git 配置里,不是 GitHub 天生的名字。
```powershell
git remote add origin https://github.com/Ki5ter/Obsidian.git
```
如果需要推送到多个远端,可以添加多个别名:
```powershell
git remote add backup https://example.com/backup.git
```
`master` 是分支名,也可以叫 `main``dev``notes`。分支可以理解为一个指向最新提交的指针。
```powershell
git push origin master
```
这条命令表示把本地 `master` 分支推送到 `origin` 远端。它不会自动推送其他本地分支。
第一次推送时常用:
```powershell
git push -u origin master
```
`-u` 会设置上游关系。之后在本地 `master` 分支上执行 `git push``git pull`Git 会自动使用 `origin/master`
## 常用检查命令
查看当前仓库状态:
@@ -126,6 +159,73 @@ git remote -v
git log --oneline --decorate -5
```
查看某个路径是否被 ignore 命中:
```powershell
git check-ignore -v --no-index -- "密码本/任意测试文件.md"
```
查看某个路径是否还被 Git 跟踪:
```powershell
git ls-files -- "密码本" "服务器迁移"
```
## .gitignore 的作用
`.gitignore` 用来告诉 Git:哪些未被跟踪的新文件不要加入版本控制。
推荐把只在仓库根目录生效的目录写成:
```gitignore
/密码本/
/服务器迁移/
```
开头的 `/` 表示仓库根目录,结尾的 `/` 表示目录。
如果只写:
```gitignore
密码本
```
也能生效,但它会匹配仓库中任何位置名为 `密码本` 的文件或目录,不如 `/密码本/` 精确。
已经被 Git 跟踪过的文件不会因为加入 `.gitignore` 自动消失。需要执行:
```powershell
git rm --cached -r -- "目录或文件名"
```
这会从 Git 跟踪列表中移除文件,但保留本地实际文件。
## 清理历史中的敏感内容
如果敏感文件已经推送到远程仓库,只在最新提交中删除还不够,旧提交里仍然可能看到。
清理历史的思路是:重写本地提交历史,让每个相关提交都不再包含敏感路径,然后强制替换远端分支。
示例:
```powershell
git filter-repo --path "密码本/" --path "服务器迁移/" --invert-paths
git fetch origin
git push --force-with-lease origin master
```
`git filter-repo` 不是 Git 自带命令,需要单独安装。`--invert-paths` 表示反转路径选择:保留其他所有路径,移除 `--path` 指定的路径。
普通 `git push` 只允许向前追加提交。重写历史后,本地提交 ID 已经变化,远端会拒绝普通 push,因此需要:
```powershell
git push --force-with-lease origin master
```
`--force-with-lease``--force` 更安全。它会检查远端分支是否仍停在本地记录的位置;如果别人已经推送了新提交,它会拒绝覆盖。
敏感信息如果已经泄露过,清理 Git 历史只是补救之一。密码、Recovery Key、Token 等应视为已经泄露,优先更换或吊销。
## Obsidian 笔记库使用 Git 的注意事项
Obsidian 笔记库适合用 Git 备份,因为大多数内容都是 Markdown 文本文件。
@@ -148,6 +248,18 @@ Obsidian 笔记库适合用 Git 备份,因为大多数内容都是 Markdown
特别大的二进制文件
```
建议忽略:
```gitignore
/.obsidian/workspace*.json
/.obsidian/cache/
/.vs/
/密码本/
/服务器迁移/
```
`workspace*.json` 是 Obsidian 的窗口和布局状态,通常和具体电脑有关。`.vs/` 是 Visual Studio 本地缓存,也不适合提交。
如果笔记库在 OneDrive 里,要注意 `.git` 目录必须真实保留在本机。否则 Git 或 Visual Studio 可能会报错,例如:
```text