简体   繁体   中英

Git branch not detached from an other branch

Hey there, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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