git - stash 时 merge 状态丢失

标签 git merge

碰巧在我们进行存储后,有关 merge 的信息丢失了。下面比较了通常的 merge 和 stash 的 merge 。

右: merge +推送

git merge release-2013-10-29
# Everything works, cool
git commit -am "Upgraded to release 2013-10-29"
git push origin dev

结果如预期, merge 提交:

enter image description here

错误:merge + stash + push

在这种情况下,我需要存储 merge 更改,以便查看 merge 前的行为。

git merge release-2013-11-06
# Conflicts fixed, but detected inappropriate behaviour
git stash
git stash pop
git commit -am "Upgraded to release 2013-11-06"
git push origin dev

结果:这次提交不再是“merge ”。我们还丢失了 merge 中包含的所有单个作者的提交,就像我会进行所有这些更改一样。

enter image description here


那么,我们不应该在 merge 时 stash 任何东西吗?那么如何避免这种行为呢?

最佳答案

当你进行 merge 时,git stores a reference to the branch you're merging in MERGE_HEAD .但似乎 git stash 没有保存引用。

您可以尝试将 MERGE_HEAD 设置回您在应用存储后 merge 的提交:

假设您要将 release-2013-11-06 分支 merge 到 master 上,并且那里的最后一次提交是 - 3be2c99,那么您可以这样做:

git stash apply --index
git update-ref MERGE_HEAD 3be2c99
git status
# All conflicts fixed but you're still merging
# ....

在应用存储时注意 --index 的用法。这是在索引中取回更改所必需的,否则您将只能在工作树中获得 stash 的更改。

P.S:理想情况下,您应该避免 stash 未提交的 merge 。

关于git - stash 时 merge 状态丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24637571/

相关文章:

git - 如何在 Git 中将最后一次提交分成两部分?

git - 从不同的存储库 pull 请求

java - "Cannot read git config"配置 Git 默认远程和 merge 时

android:允许创建一个 Activity 别名,其 targetActivity 在 aar/sdk 中

r - 不匹配列中的整个文本以供引用

R:根据列中的值合并两个数据框并返回两个数据框的所有值

Git 强制使用 HTTPS

git - 为什么 fork 同步有用?

git - 本地 git 仓库强制从远程 git 仓库更新。 (胖客户端部署)

git - 从远程服务器 pull 某个分支