将本地更改添加到非当前分支

将本地更改添加到非当前分支

本文介绍了GIT:将本地更改添加到非当前分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常发生一些局部变化,只是发现我在错误的分支上创建了它,所以我需要在提交之前切换分支。问题是当有局部变化时,我不能切换分支。有没有办法做到这一点?



显然,我可以复制更新的文件,切换分支,然后复制它们,但这看起来并不聪明!您可以在本地修改时切换分支,除非您的本地更改与两个分支之间的差异相冲突。在这种情况下,您可以使用 code>无论如何执行结帐,并执行合并变更和切换分支造成的变化。

  git checkout -m其他分支


It usually happens to me that I make some local changes, only to discover that I made it on the wrong branch, so I need to switch branch before committing. The problem is that I cannot switch branch when there are local changes. Is there anyway to do that?

Obviously, I can copy the updated files, switch branch, then copy them back, but this doesn't really seem clever!

解决方案

You can switch branches while you have local modifications unless your local changes conflict with the difference between the two branches. In this case you can use the -m or --merge option to checkout to perform the checkout anyway and perform a merge betwee changes and the changes caused by switching branches.

git checkout -m other-branch

这篇关于GIT:将本地更改添加到非当前分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:32