[英]How to create a new branch when there are existing unstaged changes in git?
I have git repo with two branches: 我有两个分支的git repo:
master orange 主橙
While I was in orange branch, I made quite a few changes in files but they are not yet added and committed on orange. 当我在Orange分支中时,我对文件进行了许多更改,但尚未在Orange上添加并提交它们。 What I want to do is to create a new branch red in which I add and commit these changes as these changes must not be in orange branch.
我想做的是创建一个新的红色分支,在其中添加并提交这些更改,因为这些更改一定不能在橙色分支中。 After that I should be able to easily switch to orange or red branch.
之后,我应该能够轻松切换到橙色或红色分支。
You don't have to do anything special. 您不必做任何特别的事情。 Create the branch, check it out, then add and commit the unstaged changes.
创建分支,将其检出,然后添加并提交未暂存的更改。
git checkout -b red
git add .
git commit
Perhaps the confusion is the wrong idea that making a branch is a big deal, like it is in SVN. 就像在SVN中一样,创建一个分支是一件大事,这可能是个误解。 All making a new branch in Git does is put a new label onto the current commit.
在Git中创建新分支的全部工作都在当前提交上放置了一个新标签。 If you're on the
orange
branch and git branch red
then orange
and red
will point to the same commit. 如果您位于
orange
分支和git branch red
则orange
和red
将指向同一提交。 Your working copy and staging area will remain the same. 您的工作副本和暂存区将保持不变。
After making red
your repository will look like this. red
后,您的存储库将如下所示。
* [red] [orange] [HEAD]
|
*
|
* [master]
After you checkout red
, add and commit then red
will advance to the new commit. 签出
red
,添加并提交,然后red
将前进到新提交。 orange
will remain at the previous commit. orange
将保留在前一次提交。
* [red] [HEAD]
|
* [orange]
|
*
|
* [master]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.