将更改的文件移到另一个分支进行签入 [英] moving changed files to another branch for check-in

查看:43
本文介绍了将更改的文件移到另一个分支进行签入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这经常发生在我身上:我写了一些代码,检查我的更改,然后意识到我不在适当的分支中来检查那些更改.但是,如果不恢复更改,我将无法切换到另一个分支.有没有办法将更改移动到另一个要在其中检查的分支?

This often happens to me: I write some code, go to check in my changes, and then realize I'm not in the proper branch to check in those changes. However I can't switch to another branch without my changes reverting. Is there a way to move changes to another branch to be checked in there?

推荐答案

git stash是你的朋友.

如果尚未提交,只需运行git stash.这样可以节省您的所有更改.

If you have not made the commit yet, just run git stash. This will save away all of your changes.

切换到要在其上进行更改的分支,然后运行git stash pop.

Switch to the branch you want the changes on and run git stash pop.

git stash有很多用途.这当然是更有用的原因之一.

There are lots of uses for git stash. This is certainly one of the more useful reasons.

一个例子:

# work on some code
git stash
git checkout correct-branch
git stash pop

这篇关于将更改的文件移到另一个分支进行签入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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