简体   繁体   English

Git分支和ls

[英]Git branch and ls

I'm not sure if this is the right place to ask this, please redirect me if not. 我不确定这是否是正确的问题,如果没有,请重定向。

I'm new to git and while learning it I stumbled upon this. 我是git的新手,在学习它的时候,我偶然发现了这个。 How does git branch branchName and 'ls' work with each other. git branch branchName和'ls'如何git branch branchName For eg: If I have a master and test branch and test branch has an extra testFile when compared to master branch. 例如:如果我有一个master和test分支,test分支与master分支相比有一个额外的testFile。 Now, while in the master branch, if I ls , I'll wont see the testFile but after switching to the test branch and ls , I'll see the testFile 现在,而在主分支,如果我ls ,我就不会看到TESTFILE但切换到测试分支和后ls ,我会看到TESTFILE

kiran@kiran-desktop:/media/kiran/Linux_Server/dev$ git branch
  master
* test
kiran@kiran-desktop:/media/kiran/Linux_Server/dev$ git checkout master
M   editor/editor_parts/syntax/operator_syntax.js
Switched to branch 'master'
kiran@kiran-desktop:/media/kiran/Linux_Server/dev$ ls
cgi-bin     index.php                    misc           underConstruction
editor      jquery-1.5.2.min.js          php.php        userManage
fileManage  jquery-ui-1.8.11.custom.css  projectManage  userPages
images      login                        test.php
kiran@kiran-desktop:/media/kiran/Linux_Server/dev$ git checkout test
M   editor/editor_parts/syntax/operator_syntax.js
Switched to branch 'test'
kiran@kiran-desktop:/media/kiran/Linux_Server/dev$ ls
cgi-bin     index.php                    misc           test.php
editor      jquery-1.5.2.min.js          php.php        underConstruction
fileManage  jquery-ui-1.8.11.custom.css  projectManage  userManage
images      login                        testFile.txt   userPages
kiran@kiran-desktop:/media/kiran/Linux_Server/dev$ 

But pwd from both branches shows the same location. 但来自两个分支的pwd显示相同的位置。

So, how does switching branches change the output of ls ( which as I understand is a function of linux) ? 那么,切换分支如何改变ls的输出(据我所知,这是linux的一个功能)?

Git, unlike in SVN what you know keeps branches in different directories, keeps only the current working branch in the repository directory. Git,与SVN不同,您知道将分支保存在不同的目录中,只保留存储库目录中的当前工作分支。

All the branches (Actually, all the objects) are stored inside the '.git' folder in the root of the repo and only the files belonging to the specific branch are present while you have checked out a specific branch. 所有分支(实际上,所有对象)都存储在repo根目录中的“.git”文件夹中,并且在签出特定分支时,只存在属于特定分支的文件。 (and those files that are not added to the repo) (以及那些未添加到repo的文件)

git checkout switches you from one branch to the other. git checkout将您从一个分支切换到另一个分支。 To do this, it replaces the files in the checked out repository with the ones from the branch. 为此,它将检出的存储库中的文件替换为分支中的文件。

Your repository is effectively the .git subdirectory. 您的存储库实际上是.git子目录。

If you do a ls -a , you'll see it: 如果你做一个ls -a ,你会看到它:

% ls -a -1
.git
.gitignore
...

Tracked files are stored in there. 跟踪文件存储在那里。 You normally only see the currently checked out branch. 您通常只能看到当前签出的分支。 When you checkout a different branch, git grabs the files from .git and you can see them with ls . 当你签出一个不同的分支时,git从.git获取文件,你可以用ls看到它们。

Have a look at the answers to this question for more information about how git works: Where can I find a tutorial on Git's internals? 有关git 如何工作的更多信息,请查看此问题的答案: 我在哪里可以找到关于Git内部的教程?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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