简体   繁体   中英

Files from other branches visible in master branch

I am learning git. I created a new NEW branch from my master branch and created a new file in NEW . Now when I switch back to master, the newly created file in NEW is visible in master branch. Is it normal? If so, how do I hide files from other branches in master branch.

Until you add it ( git add <file> ) and you commit it ( git commit -m 'My new file' ), your newly created file isn't tracked . It means that git is not aware of its existence in its index tree.

So the behaviour you describe is totally expected. This schema might help you to understand ( source ).

Try the following:

git checkout master          # start from the master branch
git checkout -b NEW          # create and switch onto the NEW branch
echo foo > bar               # create a new file
git add bar                  # track the file
git commit -m 'My new file'  # Commit the new file
git checkout master          # The file has disappeared from the working directory

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