如何将本地未提交的更改合并到另一个Git分支中? [英] How do I merge my local uncommitted changes into another Git branch?

查看:541
本文介绍了如何将本地未提交的更改合并到另一个Git分支中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Git中执行以下操作?

How can I do the following in Git?

我当前的分支是branch1,并且已经做了一些本地更改。但是,我现在意识到我实际上打算将这些更改应用于branch2。有没有一种方法可以应用/合并这些更改,以使它们成为branch2上的本地更改,而无需在branch1上提交它们?

My current branch is branch1 and I have made some local changes. However, I now realize that I actually meant to be applying these changes to branch2. Is there a way to apply/merge these changes so that they become local changes on branch2 without committing them on branch1?

推荐答案

您的文件尚未在 branch1 中提交:

Since your files are not yet committed in branch1:

git stash
git checkout branch2
git stash pop

git stash
git checkout branch2
git stash list       # to check the various stash made in different branch
git stash apply x    # to select the right one






评论,由 benjohn (请参见 git隐藏手册页):


As commented by benjohn (see git stash man page):


也可以隐藏currentl y个未跟踪(新添加)的文件,添加参数 -u ,因此:



git stash -u

这篇关于如何将本地未提交的更改合并到另一个Git分支中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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