命令行工具

安装 linux 子系统(例如 Ubuntu 20.04 LTS,需要注意是否支持 wsl2),在 cmd / powershell 中输入 bash,即可调用 linux 命令行工具
/mnt/d/ 对应系统中的 D 盘

https://docs.microsoft.com/zh-cn/windows/wsl/install-win10#update-to-wsl-2

Git

记住账号密码

Ubuntu 命令行中输入 git config --global credential.helper store,之后只需要输入一次 git 用户名和密码就会被记住

autocrlf

  1. # git 在提交时将 crlf 转换为 lf,而在检出时将 lf 转换为 crlf
  2. git config --global core.autocrlf true
  3. # 在提交时将 crlf 转换为 lf,而检出时不转换
  4. git config --global core.autocrlf input
  5. # 提交和检出代码时均不进行转换
  6. git config --global core.autocrlf false

bad signature index file corrupt

index file 在 git 里面一般指的是 .git/index 这个文件。这个文件保存的是暂存区的信息(索引信息)。可以通过 git ls-files —stage 来查看暂存区的内容。这个文件很重要!但是现在报 index file corrupt,说明这个文件已经损坏了。还好,我们有办法重新来生成这个文件:git read-tree 或者直接 git reset.
解决办法:
进入到工程目录下: cd /path/to/dir
删除或重命名 .git/index 文件: rm -f .git/index 或 mv .git/index{,.bak}
重建 .git/index : git read-tree 或者直接 git reset

Webstorm

  • Settings -> Languages & Frameworks -> Node.js & NPM: Node interpreter
    • Add WSL(Windows Subsystem for Linux)
  • Setting -> Tools -> Terminal 中配置 Shell path:
    • “cmd.exe” /k “wsl.exe”
  • Settings -> Version Controls -> Git (Webstorm 2020.2 支持 wsl2)
  • Settings -> Editor -> Code Styles -> Line Separator 设置 LF

    IDE 分析工具一直 analyzing

    点击 File -> Invalidate Caches / Restart …

端口占用

  • win10
    • netstat -ano|findstr "8080"
  • WSL
    • lsof -i:8080 可以查到 8080 端口是否被占用;kill -9 process 可以把相对应的 process 马上 kill 掉;process 指的是第一条命令出来的 PID

WSL2 问题

localhost 访问不了 https://github.com/microsoft/WSL/issues/4636
webpack hot reloading 不生效:

  1. devServer: {
  2. watchOptions: {
  3. poll: true
  4. }
  5. }

但是编译很慢,所以切换回 WSL 1: wsl --set-default-version 1

gitlab ci runner 报错:git fetch-pack: expected shallow list

升级 git 和 runner

npm i时提示sha512错误

下载 npm 包的时候,会进行包的哈希检测,以防下载的包被人恶意篡改,然而有时候因为 cnpm 与 npm 混用导致出现这个问题,可以通过以下步骤解决:

  • rm package-lock.json && npm i
  • rm -r package-lock.json node-modules && npm cache clean —force && npm i

wsl 0.0.0.0 局域网访问问题

win10 默认不能使用 0.0.0.0。需要手动开启 LAN 访问。

WSL2 Input/output error

重启wsl
wsl —shutdown
wsl