我能否在进行合并时使用git stash?

19
我正在解决一个git合并的冲突,但我想暂时回到一个干净的状态,而不会丢失我已经完成的合并工作。如果我尝试使用git stash,每个冲突未被解决的文件都会出现错误:“需要合并”。 有没有好的方法可以保存正在进行中的合并?我唯一的想法是将存储库克隆到另一个文件夹中,但这似乎过于复杂。

如果您在本地克隆存储库,则至少在Unix系统上,它不会在磁盘上保留存储库历史记录的单独副本。因此,如果您有10GB的历史记录但只有100MB的文件,则只会使用额外的100MB。 - Dietrich Epp
1
正在进行中的合并存储在索引和工作树中。鉴于“git stash”将这两个内容制作成了两个提交,你会认为这是正确的做法——但是,进行中的合并状态无法存储在提交中:它包含Git不会写入树中的元数据。“stash”脚本可以被修改以将原始索引文件内容保存到自己的Blob中,但这会变得非常棘手。我不想尝试今晚编码它。:-)重新克隆源代码库似乎是最好的快速方法。 - torek
1
克隆是为此而制作的。 - jthill
1个回答

12

你可以使用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.

1
在 Git 文档中的 Usage example - Qtax
3
需要注意的是,你应该把干净的分支放到新的工作树中,而不是你当前正在工作的分支中。 - daraul

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接