git - 解决 rebase/merge 中的单个 git 文件冲突采取他们的/采取我们的?
问题描述
在使用 git 时,假设有一个本地提交main
和一个新的远程提交origin/main
,我输入:
$ git pull --rebase
然后 git 将回退我的本地提交,应用远程提交,然后尝试合并我的本地提交。
现在假设合并失败,并且在一个二进制文件中存在冲突foo
:
You are currently rebasing branch 'main'.
(fix conflicts and then run "git rebase --continue")
Changes to be committed:
a
b
c
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: foo
我想:
- 取文件 foo 的远程版本,完全覆盖我对 foo 的本地更改
或者
- 取文件 foo 的本地版本,完全覆盖对 foo 的远程更改
我为 (1) 运行什么命令?
$ git take-remote-version-??? foo
$ git rebase --continue
我为 (2) 运行什么命令?
$ git take-local-version-??? foo
$ git rebase --continue
解决方案
一般来说,您想要解决它的方式(例如,忘记来自一个分支的更改)并不是真正正确的(您应该通过它们来查看发生了什么)。话虽如此,您获取文件的方式是在正在合并/重新定位的 2 个分支之一中,如下所示:
git show :2:path-to-file > path-to-file # get this file as it is on _my_ branch
git show :3:path-to-file2 > path-to-file2 # get this file as it is on _the other_ branch/revision
git add path-to-file path-to-file2
git rebase --continue
推荐阅读
- ios - Firebase Crashlytics iOS 隐私设置
- java - DynamoDb 模型从 Java 实体扩展而来,该实体具有其他 Java 实体的字段
- android - Natviescript-Angular Android 应用程序:错误:无法加载标签栏图标:res://
.png - typescript - 在运行下一个循环之前,我们如何确保所有的承诺都得到解决
- ruby - 如何在 Ruby 中将多个符号分配给相同的值?
- cucumber - 将黄瓜报告替换为宁静报告
- python - 如何将检测到的对象相互比较
- c# - 从 azure blob 存储资源管理器手动下载文件后文件内容丢失
- javascript - .Net Core 项目上的 JavaScript 日期无效
- python - Python 3.7 不支持赋值表达式