在克隆的github存储库中,我可以cd进入分支(文件夹),但不能进入git checkout,这是为什么?

时间:2018-07-11 12:31:46

标签: git github

这是仓库https://github.com/trekhleb/javascript-algorithms.git

我从未遇到过像以前这样的事情。

3 个答案:

答案 0 :(得分:2)

您提到的存储库中只有一个分支(“主”)。此存储库的克隆将下拉master分支到您的本地存储库。 git checkout用于签出现有分支。如果需要创建分支,可以通过运行git branch NEW_BRANCH来完成,但是您需要将其签出后才能使用。 git checkout -b NEW_BRANCH都将基于当前分支创建一个名为“ NEW_BRANCH”的新分支并将其签出。使用cd移入和移出文件夹是用于目录遍历的终端命令,与git无关。网络上到处都是git教程。我建议采取其中一些来澄清这些观点。

答案 1 :(得分:0)

该问题(及其标题)表明您可能正在考虑文件夹和分支是同一回事。在某些工具(例如TFVC)中可能或多或少是正确的,但在git中,它们是无关的东西。

分支是指向提交的指针。分支名称(和其他引用)具有层次结构,但与文件夹结构无关[1]。

每个提交都有一个TREE,代表特定时间的项目内容。提交的TREETREEBLOB对象层次结构的根,该层次结构与项目(以及检出时的工作树)的目录/文件布局平行。 / p>

如果需要,您可以使用git worktree来布局本地工作区,该工作区以类似于TFVC之类的工具将分支映射到目录。但这不是git中的默认/自然方式。


[1]好了,对nitpick来说:git可以在元数据中表示ref层次结构的一种方式涉及.git/下的文件夹/文件层次结构,但这并不总是这种情况,这与您无关通常会看到或与之互动。也就是说,它仍然与 content 的文件夹结构无关。

答案 2 :(得分:0)

对于您链接的回购。除非您使用以下命令创建了另一个分支,否则调用public class SalesRepbyId implements DataParserImplementation<Map<String,ObjectImplementation>> { private FileParserImplementation<ArrayList<String[]>> FileParser; //the Factory class that creates instances of the reflected class I wanted private ObjectFactory Factory = new ObjectFactory(); public Map<String, ObjectImplementation> Parse() { //the proeprties object which then loads properties from a file and reflects the classtype I want Properties prop = new Properties(); //loading in the classtype and casting it to the subclass of ObjectImplementation that it actually is prop.load(SalesRepbyId.class.getResourceAsStream("config.properties")); Class<? extends ObjectImplementation> Classtouse = Class.forName(prop.getProperty("ObjectImplementation")).asSubclass(ObjectImplementation.class); //construct instances of 'Classtouse' and parse the data into these dynamically typed objects //return the map that holds these objects } 不会成功执行任何操作 git checkout <Anything>git checkout -b <branch>

Mark Adelsberger很好地解释了分支与文件夹的不同之处,但我想补充一点,git checkout分支在代码版本之间移动,而cd更改代码中的位置。