将隐藏项应用于其他分支 [英] Apply stash to different branch

查看:62
本文介绍了将隐藏项应用于其他分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心在错误的分支上工作.现在,我要将所有更改都转移到正确的分支.

I was accidentally working on the wrong branch. Now I want to transfer all my changes to the correct branch.

如果我存储更改并将它们应用到正确的分支上,它将只会将未提交的更改添加到正确的分支,还是将错误分支中不存在的每个更改/提交添加到正确的分支中?

If I stash the changes and apply them on the correct branch, will it only add the uncommitted changes to the correct branch or every change/commit from the wrong branch that doesn't exist on the correct branch?

例如

错误的分支具有:

  • 提交

  • Commit a

未提交的更改b

正确的分支机构有

  • 提交c

如果我在错误的分支上执行git stash并在正确的分支中git应用stash,它将把commit转移到正确的分支吗?

If I do git stash on the wrong branch and git apply stash in the correct branch, will it transfer commit a to the correct branch?

推荐答案

我将执行一次存储,然后重置(混合操作,这样您就不会丢失更改)一个提交,存储该提交,然后更改为正确的分支,然后弹出两个藏匿处.

I would do one stash, then reset (mixed so you don't lose the changes) the a commit, stash that, then change to the correct branch and pop both stashes.

git stash save "b"
git reset HEAD~
git stash save "a"
git checkout correct-branch
git stash pop
git commit -m "a"
git stash pop

这篇关于将隐藏项应用于其他分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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