git 在交互式变基期间,如何在不中止整个变基的情况下重新启动当前合并冲突?[副本]

thigvfpy  于 2023-09-29  发布在  Git
关注(0)|答案(1)|浏览(119)

此问题已在此处有答案

git: How to redo a merge conflict resolution (before committing the merge)?(3个答案)
16天前关闭
我在做一个交互式的变基。我已经--continue d 3次了,但是我对当前的合并冲突感到困惑,想重新开始。如何重新启动 this 合并冲突而不丢失所有以前的工作?
我已经注解了git status说:

interactive rebase in progress; onto 44444
Last commands done (2 commands done):
   pick 3333333 My edits
   pick 2222222 Removed some gibberish
Next commands to do (8 remaining commands):
   pick 1111111 Personal changes
   # not sure what this is, but what little research I've done makes it seem irrelevant
  (use "git rebase --edit-todo" to view and edit) 
You are currently rebasing branch 'branch' on '44444'.
  (fix conflicts and then run "git rebase --continue")
  # I don't want to skip, I want to restart
  (use "git rebase --skip" to skip this patch)
  # I don't want to go all the way back to the beginning, I only want to restart the 44444 merge conflict.
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  # this didn't revert my merge conflict changes
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution) 
        both modified:   file.py

git restore --staged之后,我在没有--stage的情况下再次尝试。现在显示为nothing to commit, working tree clean
如何重置 * 仅 * 此合并冲突?

gzszwxb4

gzszwxb41#

我不确定this是一个直接的重复还是一个答案相同的不同问题,但是对文件执行此操作会使提交返回到其原始的合并冲突状态:

git checkout -m -- file.txt

以下是checkout -m的官方文档:

-m, --merge

切换分支时,如果您对一个或多个文件的本地修改在当前分支和要切换到的分支之间不同,则命令将拒绝切换分支,以便在上下文中保留您的修改。但是,使用此选项,将完成当前分支、工作树内容和新分支之间的三方合并,您将位于新分支上。
当发生合并冲突时,冲突路径的索引条目将保持未合并状态,您需要解决冲突并使用git add(或git rm,如果合并导致删除路径)标记已解决的路径。
从索引检出路径时,此选项允许您在指定路径中重新创建冲突合并。
当使用--merge切换分支时,暂存的更改可能会丢失。
您可以执行以下操作以一次还原所有文件:

git checkout -m -- .

相关问题