Git traffics in just one sort of entity: commits. A commit is basically a snapshot of the entire state of your project at the moment it is created — all of its files, including all of its folders (because a file's "name" implies the names of any folders that contain it). [I'm simplifying; in actual fact, you are allowed to tweak the staging area that is used to form each commit. But just pretend that what I said is true.]
The commits are invisible and are encoded in a way that is meaningless to you. Thus there are no actual files that belong to you or that you can even see; all there is, is a series of entire expressions of the entire state of your project, hidden inside Git's repository.
However, that would not be very useful to you, so every time you checkout a commit, including when you switch to a different branch, Git copies the contents of that commit out into a visible area called the working tree so that you have something to work with.
So that's all that's happening here. You say "Git, switch to branch a
" and Git obligingly grabs the last commit along that branch and replaces the contents of the visible area, the working tree, with copies of the files that it contains — reproducing precisely the entire state of the project at the moment that commit was created.
Think of it as a series of family photographs, taken over time. Some family members are born; some die. At each stage, a new photo is taken, showing the family members that are currently alive, at the ages that they currently are. But we can also do time travel: we can turn any photo into a real family. That is all you are doing when you switch branches: you are selecting one photo and saying, "I want this to be my current reality." In response, the photo is indeed faithfully reproduced so that you can work with it as reality. If a family member was present in the photo, that family member is present in your reality when you check out that photo; if a family member was not present in the photo, that family member is not present in your reality when you check out that photo. It's basically as simple as that.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…