Shopify CLI 与 Headless

shopify theme push 只想上传指定文件怎么加参数

现象#

只改了 sections/header.liquid,执行一次 shopify theme push 后线上 templates/index.json 也被回滚成本地版本,首页排版被打乱。

原因#

  • 不带参数时 push 做全量比对,本地缺失的远端文件默认被删除,除非加 --nodelete
  • --only 只限制上传范围,不参与删除判定,远端多余文件仍会被清掉
  • --only 的通配符由 CLI 自行展开,不加引号会先被 shell 展开成多个真实路径
  • .shopifyignore 与 --ignore 取并集,误以为 --only 能覆盖已经写进忽略文件的条目

处理步骤#

  1. 只推目标文件并禁删:shopify theme push -o sections/header.liquid -n
  2. 多文件重复传参:--only 'snippets/*.liquid' --only 'assets/*.css'
  3. 排除商家设置:--ignore config/settings_data.json,避免覆盖后台配色
  4. 先推未发布主题验证:shopify theme push --unpublished --json
  5. 确认无误再单独发布:shopify theme publish --theme 123456,不要用 push -p 直接上线

验收标准#

push 输出只列出被 --only 命中的文件,后台 templates/index.json 的更新时间保持不变。

本文由 风格技术 技术团队整理,适用于 Shopify 标准版与 Plus 店铺。Shopify 平台能力迭代较快,具体操作路径与字段以官方文档和店铺后台实际版本为准。