开发者

Git branch not detached from an other branch

Hey the开发者_运维问答re, i'm bumping my head against the wall for a while now, i'm trying to understand something with git branches.

I have a repository with two branches. Branch A and B, i have done some modifications in my branch A (which are not commited yet) and i would like to create a new branch C based on the A branch. To do that i'm using git checkout -b branchC, when i switch to this branch C and that i try to edit one the files that i had modified previously, the new modifications are also applied on the previous branch.

I'm sure that it's not normal, don't you agree? Am I doing something wrong with the branching system?

Thanks for the help.


When you are editing your files, you are not modifying the branch. You have to commit your changes first to make them end up on the current branch. So if you just switch between A and C, the files in your working tree are still listed as modified.


The modifications you do don't belong to the branch you're working on. Whenever you switch branches, the modified-yet-uncommitted files remain as modified-yet-uncommitted. This is the expected behaviour in git. And any other VCS for that matter - version control systems don't acknowledge changes to your workspace until you tell them to. Until then they are your mods, not the VCS's.


You might want to look at the "git stash" command ("git stash --help" or "man git-stash") if you don't want to commit your changes yet for some reason. This lets you put your modified files "away" and switch to different branches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜