切换分支而不接触工作树? [英] Switching branches without touching the working tree?

查看:105
本文介绍了切换分支而不接触工作树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在一个调试分支上,并且想切换到主分支,而不修改工作树(保持它在调试分支中的样子),所以我可以将一些更改提交到主分支。

I am currently on a debug branch, and would like to switch to the master branch, without modifying the working tree (leave it the way it is in the debug branch), so I can commit some of the changes into the master branch.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

虽然你应该小心使用这个命令,但你可以重置你的头以指向master而不用改变索引或工作树:

Although you should be careful with this command you can reset you head to point at master without changing the index or working tree with:

git symbolic-ref HEAD refs/heads/master

您应该重置索引,以便有选择地应用你的工作树的变化,否则你可能会最终提交master和调试分支之间的所有差异,这可能是一件坏事。

You should probably reset the index so that you can selectively apply your working tree changes otherwise you may end up committing all the differences between master and the debug branch which is probably a bad thing.

git reset

完成提交后,您可以返回到调试分支:

Once you've made the commit that you want to make you can return to your debug branch with:

git symbolic-ref HEAD refs/heads/debug-branch
git reset

这篇关于切换分支而不接触工作树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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