简体   繁体   中英

Why aren't my files in my project changing when I switch from a branch to master?

I created a new git repository in my project:

git init
git add -A
git commit -m 'init'

I then created a branch:

git checkout -b 'test1'

I then went to a file and changed something, and then switched back to master:

git checkout master

VS.NET didn't say it was going to reload the file, I closed the solution and opened it again and the update I made in the test1 branch was still there even though I am in my master branch now.

What am I missing?

Unless you've committed the changed file, the change doesn't belong to any particular branch yet - this allows you to make a change and then decide which branch you want to commit it to.

If you've committed the change in the test1 branch and then updated to the master branch, the file would have changed back to the original version.

Git won't overwrite a file you edited that it is 'tracking' unless you have commited those changes. ie git know that you had edited it and so left it as it was, hence VS won't give any warning, because as far as it is concerned, nothing happened. That's as I understand it.

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