简体   繁体   English

GIT-在分支之间切换而不混合文件

[英]GIT - Switching between branches without mixing files

I'm new to git so I'm trying to understand how this works. 我是git的新手,所以我试图了解它的工作原理。 I currently have master checked out. 我目前有主人退房。 I made some changes to master, lets say I added a logo but I haven't pushed the changes yet. 我对母版进行了一些更改,可以说我添加了徽标,但尚未推送更改。

I then switched to another branch. 然后我切换到另一个分支。 In this branch I assumed that this would be a fresh checkout of master, but I see my development logo file. 在该分支中,我假设这将是master的全新签出,但是我看到了我的开发徽标文件。 Shouldn't this not be here since it's another branch? 因为它是另一个分支,所以不应该不在这里吗? Let me know if I've got this concept all wrong. 让我知道我是否完全错误地理解了这个概念。

To make sonething part of a branch, you need to commit it to that branch. 为了使分音成为分支的一部分,您需要将其提交到该分支。 If you have uncommitted work in your checkout, the changes will be kept when switching the branch (as long as there are no conflicts). 如果您在结帐时有未完成的工作,则在切换分支时将保留更改(只要没有冲突)。

Committing changes to a branch does not mean that they are there forever. 将更改提交分支并不意味着它们永远存在。 You still need to push the changes to make them (in a way) permanent. 您仍然需要推动更改以使其永久(以某种方式)。

So if you want to work in another branch temporarily, you can commit your changes, switch the branch, work there, commit that work, switch back to the old branch, execute "git reset HEAD~" to get you earlier committed work back as uncommitted changes and continue from there. 因此,如果您想暂时在另一个分支中工作,则可以提交更改,切换分支,在那儿工作,提交该工作,切换回旧分支,执行“ git reset HEAD〜”,以使您之前提交的工作恢复为未提交的更改,然后从那里继续。

或者,使用git stash save / git pop来保存/恢复切换分支之前/之后的工作状态。

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

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