如何将我的本地未提交更改合并到另一个Git分支中?(How to merge my local uncommitted changes into another Git branch?)

825 IT屋

我该如何在git中做到这一点:



我当前的分支是分支1,我做了一些本地更改。不过,我现在意识到我实际上是想将这些更改应用于branch2。有没有办法应用/合并这些更改,以便它们在branch2上成为本地更改而不在branch1上提交它们?

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



  git存储
git checkout branch2
git stash pop




  git stash 
git checkout branch2
git stash list#检查在不同分支中创建的各种存储
git stash apply x #选择正确的一个





评论通过 benjohn (见 git stash 手册页):


当前未跟踪的(新添加的)文件,添加参数 -u ,所以:



< pre> git stash -u

How can I do this in git:

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?

解决方案

Since your files are not yet committed in branch1:

git stash
git checkout branch2
git stash pop

or

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

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

To also stash currently untracked (newly added) files, add the argument -u, so:

git stash -u

本文地址:IT屋 » 如何将我的本地未提交更改合并到另一个Git分支中?

相关文章: