[英]git switch from one branch to another without carrying the changes in the current branch
I don't know if this is normal in Git but whenever I move from one branch to another, the changes in that current branch that I am in is carried on to the branch where I switch on. 我不知道这在Git中是否正常,但是每当我从一个分支移动到另一个分支时,我所在的当前分支中的更改都会继续到我打开的分支中。
For example, I have the master
branch and then I created a branch2
. 例如,我有
master
分支,然后创建了branch2
。 I added some files to branch2
and committed all of it. 我向
branch2
添加了一些文件,并全部提交了。 Then I create a new branch and switch to it using git checkout -b branch3
. 然后创建一个新分支,并使用
git checkout -b branch3
切换到该分支。 The files that I have added on branch2
is now on branch3
as well. 我在
branch2
上添加的文件现在也在branch3
。 But what I want is only the things that I have on my master
branch. 但是我想要的只是我在
master
分支上拥有的东西。
The only solution that I found so far is to switch to the master
branch first and then use git checkout -b branch3
so that I won't get the changes from branch2
. 到目前为止,我发现的唯一解决方案是先切换到
master
分支,然后使用git checkout -b branch3
这样我就不会从branch2
那里得到更改。
Is there a shortcut to this? 有捷径吗? Am I doing something wrong?
难道我做错了什么? Thanks in advance.
提前致谢。
As a shortcut to switching to the master branch before you make branch3
, you can use git checkout -b branch3 master
. 作为在创建
branch3
之前切换到master分支的快捷方式,可以使用git checkout -b branch3 master
。
This second argument is called the "start point", and it defines the branch that the new branch should be based on. 第二个参数称为“起点”,它定义了新分支应基于的分支。
For more details here about the git branch
command, see the git-scm docs for git branch . 有关
git branch
命令的更多详细信息,请参阅git branch
的git-scm文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.