# copying your commit(s) to separate branchgit checkout <last_sync_commit>git checkout -b tempgit cherry-pick <last_local_commit>
git checkout mastergit reset --soft HEAD~1 # or how many commits you have only on local machinegit stash # safer, can be avoided using hard resetting on the above linegit pullgit cherry-pick <last_local_commit>
# deleting temporary branchgit branch -D temp
$ git pull --depth=1fatal: refusing to merge unrelated histories$ git statusYour branch and 'origin/main' have diverged,and have 1 and 1 different commits each, respectively.
根据上面的答案,会导致两个分支发散到不同的“线”上,所以Git认为这是不相关的历史。
---a---b---main\ \x x x x diverged, cannot be merged anymore\ \---?---?---?---c(origin/main)