简体   繁体   English

Git分支:本地创建的分支会自动与本地主分支合并

[英]Git Branching: Locally created branch is automatically merging with local master branch

I'm using Git as my version control software. 我使用Git作为我的版本控制软件。 I've initialized and made the initial commit to my local repository. 我已经初始化并向本地存储库进行了首次提交。 Then I'm creating another branch for an UI update as following. 然后,我将为UI更新创建另一个分支,如下所示。

git checkout -b "ui-update"

The issue is, when I make a change to the ui-update branch and switch back to my master branch (without comiting those changes), the changes that are made, are also reflected in my master branch. 问题是,当我对ui-update分支进行更改并切换回我的master分支(不撤消那些更改)时,所做的更改也会反映在我的master分支中。 Also, it is not giving an error when I'm switching to my master branch. 另外,当我切换到我的master分支时,它没有给出错误。 This is how I switch to my master branch. 这就是我切换到主分支的方式。

git checkout master

However, when I make a commit to the ui-update branch, those changes are only reflected in that branch (not in master). 但是,当我提交到ui-update分支时,这些更改仅反映在该分支中(不在master中)。

Is this the default behavior of Git? 这是Git的默认行为吗? Or am I doing something wrong here? 还是我在这里做错了什么?

Modifications are not a part of a branch while you don't commit them. 当您不提交修改时,修改不属于分支。

So, before your 所以,在你

git commit -m "my commit"

all you do is not binded on anything and you can checkout a branch taking your modifications with you without affecting the current branch 您所做的一切都不受任何约束,您可以签出一个分支,并随身进行修改,而不会影响当前分支

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

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