为什么我必须在切换分支之前隐藏/提交更改? [英] Why do I have to stash / commit my changes before switching branches?

查看:1097
本文介绍了为什么我必须在切换分支之前隐藏/提交更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这很烦人,因为我想快速切换分支并做一些事情,然后切换回我以前的工作。我意识到我可以隐藏然后检索隐藏,但是每次都必须输入这些行:/ b

有什么办法可以避免这样做吗?

p>

我也觉得这很烦人,因为我保留了大约5或10个功能分支,并且很难管理哪些分支需要检索以及哪些分支需要保留继续工作。

解决方案

您可以使用 git checkout ' s - 合并 -m )选项。

使用它会导致三向合并完成切换分支时。如果发生这些冲突,您可能需要解决合并冲突。



至于为什么会发生这种情况,手册列出了


切换分支时,如果您对当前分支与切换到的
分支之间的一个或
多个文件进行本地修改,则该命令拒绝切换
分支,以便在上下文中保留您的修改。


请参阅 git checkout 手册页了解更多详情

I find this to be annoying because I would like to quickly switch branches and do something and then switch back to what I was working on before. I realize I can stash and then retrieve stash, but then I have to type those lines every time :/

Is there any way to avoid having to do this?

I also find it annoying because I keep about 5 or 10 feature branches and it gets hard to manage which ones have a stash that needs to be retrieved and which ones are good to keep working on as they are.

解决方案

You could use git checkout's --merge(-m) option.
Using it causes a three-way merge to be done when switching branches. You may need to resolve merge conflicts if these occur.

As to why this occurs, the manual states

When switching branches, if you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command refuses to switch branches in order to preserve your modifications in context.

See the git checkout manual page for more details

这篇关于为什么我必须在切换分支之前隐藏/提交更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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