You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

是否存在可替代git checkout --theirs/--ours的git reset等效命令?

在变基(Rebase)中替代git checkout --ours/--theirs <file>的命令

首先得明确:变基过程里的--ours和--theirs含义和普通合并冲突时是反过来的——

  • --ours对应的是你当前正在变基的分支(也就是执行git rebase前checkout的分支)
  • --theirs对应的是你要变基到的目标分支

如果你不想用git checkout,可以用Git 2.23版本之后推出的git restore命令来替代,完全等效:

  • 要保留当前变基分支的文件版本(对应git checkout --ours <file>):
    git restore --ours <file>
    
  • 要采用目标分支的文件版本(对应git checkout --theirs <file>):
    git restore --theirs <file>
    

git restore是官方专门用来拆分git checkout歧义功能的命令之一,和git switch配合,正好能替代git checkout的大部分场景,完美契合你不想用git checkout的需求。

内容的提问来源于stack exchange,提问作者Karel Bílek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 16:07:07