简体   繁体   English

git从一个分支切换到另一个分支,但不对当前分支进行更改

[英]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 branchgit-scm文档

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

相关问题 GIT-如何在不进行更改的情况下切换分支,反之亦然 - GIT - How to switch Branch without carrying changes and viceversa Git开关分支,无需在当前分支上提交和传输更改 - Git switch branch without commiting and transferring the changes on the current branch 切换分支并在Git中保留当前分支更改 - Switch a branch and preserve current branch changes in Git 将更改从一个分支应用到另一个分支,而不影响 git 历史记录 - Apply changes from one branch to another without affecting git history Git 将更改从一个分支复制到另一个分支,而不提交源分支中的更改 - Git copy changes from one branch to another without committing the changes in source branch 在不影响当前分支的情况下从另一个分支获取更改 - Get changes from another branch without affecting current branch at all 如何通过git将更改从一个分支拉到另一个分支 - How to pull changes from one branch to another branch through git 如何将更改从一个分支移动到另一个分支 git? - How to move the changes from one branch to another branch git? 如何从一个git分支更改到另一个分支 - How to take changes from one git branch to another branch 如何在Visual Studio中打开另一个GIT分支而无需提交对当前的更改? - How can one in Visual Studio open another GIT-branch without need to commit changes to the current one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM