如何在git中合并多个窗口 [英] How to combine multiple stashes in git

查看:381
本文介绍了如何在git中合并多个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是过去两周分支前端的管道。 Stash @ {3} 是自 Stash @ {1} 之后的所有代码(不包括两个小提交)

|微小的承诺

|微小的承诺

|两星期前巨额批量提交,现在重新分配并移动到 Stash @ {1}



我的工作树目前干净。

Stash @ {1} 是两星期前通用开发代码批量提交的内容(这应该已经隐藏在第一个地点)。此提交已被撤消并移至存储位置。

Stash @ {3} 是自从 Stash @ {1} (减去一些已提交的更改)。



我需要在工作树中将这两个组合在一起,以便从这个巨大的工作池中进行一些提交。



我运行了 git stash apply stash @ {1} 然后我试过了:

git stash apply stash @ {3}

git stash show -p | git stash apply stash @ {3}



但是在这两种情况下,我都会得到'dirty working tree'。我怎样才能将这项工作合并在一起?因为 stash @ {3} 更新,所以我希望它在任何有冲突的地方替换 stash @ {1}

解决方案

如果与工作树中的修改文件没有冲突,则只能应用存储,因此,首先请确保存在在 git status 中没有修改过的文件,如果有的话,提交它们。然后执行:

  git stash apply stash @ {1} 
git commit -a
#输入您的提交消息
git stash apply stash @ {3}

然后你可以创建一个新的提交或修改前一个来合并它们。您可能需要在每次申请后解决合并冲突。



另外,如果您决定使用 git stash pop 而不是应用,请注意 stash @ {3} 会变成隐藏@ {2} ,因为第一个弹出。


This is a pipeline on branch frontend over the last two weeks.

| Stash@{3} is all code since Stash@{1} (excluding the two tiny commits)
| Tiny Commit
| Tiny commit
| Huge bulk commit two weeks ago, now rebased and moved to Stash@{1}

My working tree is currently clean.
Stash@{1} is the contents from a bulk commit of general development code two weeks ago (this should have been stashed in the first place). This commit was undone and moved to stash.
Stash@{3} is the newest work on that tree since Stash@{1} (minus a couple of changes that have been committed).

I need to combine these two stashes together in my working tree so I can make a number of commits from this huge pool of work.

I ran git stash apply stash@{1} then I tried:

git stash apply stash@{3}
git stash show -p | git stash apply stash@{3}

but I get 'dirty working tree' in both cases. How can I merge this work together? Because stash@{3} is newer, I want it to supersede stash@{1} wherever there are conflicts.

解决方案

You can only apply a stash if there are no conflicts with modified files in the working tree, so, first, ensure there are no modified files in git status, if there are, commit them. Then do:

git stash apply stash@{1}
git commit -a
# Enter your commit message
git stash apply stash@{3}

Then you can either make a new commit, or amend the previous one to combine them. You may need to resolve merge conflicts after each apply.

Also, if you ever decide to use git stash pop rather than apply, note that stash@{3} would become stash@{2} since the first one was popped off.

这篇关于如何在git中合并多个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆