Lixx

Stay hungry, stay foolish

最近重装了 vscode 和 git,发现在 vscode 中直接使用 git bash 终端。估计是因为没装到默认路径或者没添加 path 导致 vscode 找不到 git bash。

terminal profile option

解决方法

在 vscode 的 setting.json 中添加相应的设置即可。

  1. ctrl + , 打开 Settings 页面。

    1. 搜索 @feature:terminal profile window
    2. 找到 Terminal › Integrated › Profiles: Windows,
    3. 选择Edit in settings.json
      Terminal › Integrated › Profiles: Windows
  2. settings.json 文件中,向 "terminal.integrated.profiles.windows": { } 对象中新增 git bash 的设置。

    1
    2
    3
    4
    5
    "Git Bash": {
    "source": "Git Bash", // A profile source that will auto detect the paths to the shell. Note that non-standard executable locations are not supported and must be created manually in a new profile.
    "path": "D:\\Scoop\\apps\\git\\current\\bin\\bash.exe", // A single path to a shell executable or an array of paths that will be used as fallbacks when one fails.
    "icon": "terminal-bash" // A codicon ID to associate with the terminal icon.
    }

    其中起作用的 path 属性,sourceicon 属性可删除,icon 也可以设置为自己喜欢的图标。
    注意将 path 属性设置为你自己的路径。一般位于 ......\\git\\bin\\bash.exe
    settings.json example

  3. 保存设置后,应该就能在新建终端选项中看到 git bash 了。如果没有,则检查 path 属性的路径是否正确。
    terminal profile option

  4. 如果有需要,可通过 Terminal › Integrated › Default Profile: Windows 将 git bash 设置为默认终端。
    Terminal › Integrated › Default Profile: Windows
    terminal profile option

之前一直觉得在 Windows 上使用 git-bash (MINGW64)运行 hexo 速度慢。今天在 Windows 10 和 WSL 中分别测试了一下,结果表明这是真的,不是错觉。

Windows 10

在 Windows 10 中使用 git-bash 运行

1
2
3
4
rm -rf public db.json
time pnpm build

# pnpm build = hexo generate

得到结果,用时约为 11 秒。

1
2
3
real    0m11.384s
user 0m0.000s
sys 0m0.015s

WSL

在 WSL 中 git clone 我的博客仓库,运行同样的命令

1
2
3
4
rm -rf public db.json
time pnpm build

# pnpm build = hexo generate

用时仅为 6.5 秒,几乎相差一倍。

1
2
3
real    0m6.503s
user 0m11.209s
sys 0m1.927s

我分别进行了多次测试,数据差别不大。为了简洁只展示其中一次的数据。

不过,我一般使用 Github Action 进行构建博客,在 Windows 上速度如何,影响并不大。
但是,如果其他的应用、工具也有这样问题,那么对效率影响还是挺大的。

我很早就在我的网站上开启了这个功能。并加入了 hstspreload.org ,但今天偶然发现 HSTS Preload 并没有生效。原因是我之前迁移网站时,将 cloudflare 的页面规则修改了。

问题

今天偶然发现,对于已经在 git 中 commit 的文件,修改其文件名大小写,git 不会记录文件名的变化。上网搜索发现不少人都遇到过这个坑。

解决

对于已 commit 的文件,使用 git mv <src> <dest>
例如:

1
git mv file_name.ts File_Name.ts

然后进行 commit,push 即可。

后续

为以免后患,可以修改 git 配置项。
core.ignorecase 修改为 false

1
git config core.ignorecase false

修改后建议检查一下 .git/config 中配置是否正确。这个指令似乎存在奇怪的 bug (?)

网上有的文章修改 .git/info/sparse-checkout 以进行 sparse checkout,实际上 git 有自带的 sparse-checkout 命令。

操作步骤

带参数克隆仓库

1
git clone --no-checkout --sparse --filter=blob:none [email protected]:<username>/<repo>.git
参数含义
--no-checkout不 checkout 到 HEAD
--sparse开启 sparse-checkout 功能
--filter=blob:none不下载 blob 对象(重要,否则还是需要下载大量数据)

refs: git clone

进入目录

1
cd <repo>

指定需要 checkout 的目录

1
git sparse-checkout add <path/to/>

refs: git sparse-checkout

注意:默认情况下 sparse-checkout 为 cone 模式。默认情况下 sparse-checkout 会包含根目录下的文件。
cone 模式存在诸多问题,因此 git 官方文档不建议使用非 cone 模式。
详见文档。

进行 checkout

1
git checkout [<branch>]

可以看到下载的数据和等待的时间大大减少,

1
2
3
4
5
6
7
8
9
remote: Enumerating objects: 31, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 31 (delta 0), reused 0 (delta 0), pack-reused 20
Receiving objects: 100% (31/31), 616.91 KiB | 636.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.
Updating files: 100% (32/32), done.
Already on 'main'
Your branch is up to date with 'origin/main'.

在 Windows 下,Docker Desktop 的安装位置默认在 C 盘,WSL 的数据位置也默认在 C 盘。C 盘分区小就很难受了。

网上有通过修改注册表和建立链接来修改 Docker Desktop 安装位置的方法,也有通过导出导入 WSL 数据 实现修改 WSL 数据位置的方法。
但这些都比较麻烦,实际上 Docker 的安装程序有提供修改位置的接口,使用命令行安装即可指定安装位置和数据位置,详见 Install Docker Desktop on Windows

今天为一个仓库执行 pnpm i 时出现错误 ERR_PNPM_UNEXPECTED_PKG_CONTENT_IN_STORE

使用 pnpm store prune 后依然出错。

最后用 rm -rf $(pnpm store path) 解决。代价是要重新下载包。

一句命令行删除 github 上的仓库

总是记不住命令,每次都要搜索。自己记录一下,方便查找。