简体   繁体   English

如何在不提交更改的情况下结帐到新分支?

[英]How to checkout to the new branch without committing changes?

I cloned the development branch from a gitlab repo into my local machine(window).我将 gitlab 存储库中的development分支克隆到我的本地机器(窗口)中。 After that I was supposed to create a new branch from this development branch by git checkout -b new_branch but I forgot to do that and I did all the changes inside the development branch itself.之后,我应该通过git checkout -b new_branch从这个development分支创建一个新分支,但我忘了这样做,我在development分支本身内部进行了所有更改。 I just remember it while pushing(my bad).我只是在推动时记住它(我的不好)。

Now I want to create new branch from this development branch and want to keep all these changes of the development branch(which are not pushed and should not be pushed) to this newly created branch.现在,我想从这个创建新分支development分支,并希望保持所有这些变化development的分支(未推,不应该推)到这个新创建的分支。 How can I do this ?我怎样才能做到这一点 ?

This is a very common mistake people make when using Git, and it isn't just beginners who do this by accident.这是人们在使用 Git 时经常犯的一个错误,而且不仅仅是初学者无意中这样做。 Assuming you haven't yet committed your work, you might even be able to just checkout a new branch:假设你还没有提交你的工作,你甚至可以签出一个新的分支:

# from development
git checkout -b new_branch

Then, commit your work and you should be good to go.然后,提交你的工作,你应该很高兴。 If, for some reason, you can't create a new branch from development , another easy option would be to just stash your work, then create the branch and apply the stash:如果由于某种原因,您无法从development创建新分支,另一个简单的选择是只存储您的工作,然后创建分支并应用存储:

# again, from development
git stash
git checkout -b new_branch
# from new_branch
git stash apply

Again commit your work when it is done to this new branch.完成此新分支后,再次提交您的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM