我可以 git stash 正在进行的合并吗?

Rus*_*uss 12 git merge git-stash

我正在解决 git 合并的冲突,但我想暂时恢复到干净的状态,而不会丢失我已经完成的合并工作。如果我尝试 git stash,对于尚未解决冲突的每个文件,我都会收到错误消息:“需要合并”。

有没有保存正在进行的合并的好方法?我唯一的想法是将 repo 克隆到不同的文件夹中,但这似乎过分了。

Xan*_*fer 10

您可以使用该git worktree命令在不同的文件夹中添加新的工作树。这就像第二个索引和工作树,但使用相同的 git repo。man git-worktree

   Manage multiple working trees attached to the same repository.

   A git repository can support multiple working trees, allowing you to check out
   more than one branch at a time. With git worktree add a new working tree is
   associated with the repository. This new working tree is called a "linked working
   tree" as opposed to the "main working tree" prepared by "git init" or "git clone".
   A repository has one main working tree (if it’s not a bare repository) and zero or
   more linked working trees.
Run Code Online (Sandbox Code Playgroud)

  • 可能需要注意的是,您会将“干净”分支放入新的工作树中,而不是您现在正在处理的工作树中。 (3认同)