Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

github - Git project showing separate folder structure for separate branches

There is a folder structure available at this project that contains a folder "root" that contains the files I want to use. But When I checkout the user/roboyoshi branch there, then it shows me another folder, also named "root" that contains a separate set of files than the "root" from the master branch. I downloaded the repo and cannot find the files from the branch within the extracted archive (Only the files from the root folder of the master branch)

I am new to Git, and I was expecting a super-folder where all the directories are present and some of them being hidden on per branch basis, but that is not the case. Where exactly are the contents of the branch user/roboyoshi coming from?

Is this a feature of git that I don't know (fyi, I am a Git newbie) where each branch can live within separate folders or is each branch being told to track only specific files within the same folder "root"?

question from:https://stackoverflow.com/questions/65907159/git-project-showing-separate-folder-structure-for-separate-branches

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...