# Plane Fork 仓库同步指南 ## 架构 - **upstream**: https://github.com/makeplane/plane (官方) - **origin**: https://git.pchuan.top/chuan/plane.git (自托管,保持干净) 同步状态通过commit message中的upstream hash记录。 ## 环境准备 ```bash git clone https://github.com/makeplane/plane.git -b preview cd plane git remote add upstream https://github.com/makeplane/plane.git git remote remove origin git remote add origin https://git.pchuan.top/chuan/plane.git git pull upstream preview ``` ## 初始化(一次性) ```bash # 1. 获取当前upstream的最新commit hash UPSTREAM_HASH=$(git rev-parse upstream/preview) # 2. 创建孤立分支,只保留当前代码 git checkout --orphan clean-preview git add . git commit -m "Initial commit: Plane Synced from upstream: $UPSTREAM_HASH" # 3. 删除旧分支,重命名新分支 git branch -D preview git branch -m clean-preview preview # 4. 推送到origin git push -u origin preview --force-with-lease ``` ## 后续同步流程 每当upstream有新增commit时: ```bash # 1. 从历史记录中找到最近的一次同步点(处理origin有自己改动的情况) LAST_SYNC=$(git log --all --grep="Synced from upstream:" --pretty=format:"%b" | grep "Synced from upstream:" | head -1 | awk '{print $4}') # 2. 获取当前upstream最新hash git fetch upstream CURRENT_UPSTREAM=$(git rev-parse upstream/preview) # 3. Cherry-pick新增的commit(从上次同步点到现在) git cherry-pick ${LAST_SYNC}..${CURRENT_UPSTREAM} # 4. 重新提交,更新upstream hash git reset --soft HEAD~1 git commit -m "Update: cherry-pick from upstream Synced from upstream: $CURRENT_UPSTREAM" # 5. 推送到origin git push origin preview --force-with-lease ``` ## 查看待同步的新增commit ```bash # 从历史记录中找到最近的一次同步点(处理origin有自己改动的情况) LAST_SYNC=$(git log --all --grep="Synced from upstream:" --pretty=format:"%b" | grep "Synced from upstream:" | head -1 | awk '{print $4}') # 查看新增commit git fetch upstream git log ${LAST_SYNC}..upstream/preview --oneline ``` ## 快速脚本 保存为 `sync-upstream.sh`: ```bash #!/bin/bash git fetch upstream # 从历史记录中找到最近的一次同步点(处理origin有自己改动的情况) LAST_SYNC=$(git log --all --grep="Synced from upstream:" --pretty=format:"%b" | grep "Synced from upstream:" | head -1 | awk '{print $4}') CURRENT=$(git rev-parse upstream/preview) echo "Cherry-picking from $LAST_SYNC to $CURRENT..." git cherry-pick ${LAST_SYNC}..${CURRENT} git reset --soft HEAD~1 git commit -m "Update: cherry-pick from upstream Synced from upstream: $CURRENT" git push origin preview --force-with-lease ``` ## 注意事项 - origin/preview保持孤立,仅由初始commit + 同步commit组成 - 同步hash记录在每个commit的message中,便于追溯 - cherry-pick如遇冲突,手动解决后 `git cherry-pick --continue` - 最后一步需要 `--force-with-lease` 是因为要重写最新commit