git 工作目录在哪里?
各位编码员,今天是我第一次在 Mac 上使用 Tower 深入研究 git - 人生苦短,不能乱搞命令行;)
我确实阅读了一些介绍和教程,但没有一个解决我正在写的问题。我在理解 git 与 SVN 中的工作目录概念时遇到一些困难。
我做了什么:
- 我创建了一个本地存储库并将其指向我的项目文件所在的文件夹。
- 添加并提交了文件夹中的所有文件。
- 编辑了一个文件。显示为已修改。
- 添加并提交文件。
这些步骤奏效了。
到目前为止,我还没有被要求提供工作目录的位置,并且我无法签出主 HEAD(该选项已禁用)。我的问题是:我的原始文件夹是否充当结帐工作目录?结账命令什么时候起作用?只有当我有多个分支时它才起作用吗?
希望在我进一步讨论之前有人能澄清这一点。
Fellow coders, today is my first dive into git using Tower on the Mac - life's too short to mess with the command line ;)
I did read a few intros and tutorials but none addressed the question I'm writing about. I'm having some trouble understanding the working directory concept in git vs. SVN.
What I did:
- I created a local repo and pointed it to the folder where my project files are.
- Added and committed all the files in the folder.
- Edited a file. Showed up as modified.
- Added and committed the file.
These steps worked.
So far I have not been asked for the location of the working directory and I cannot checkout the master HEAD (the option is disabled). My question is: Is my original folder acting as the checkout working directory? When does the checkout command work? Does it only come to play when I have multiple branches?
Hope someone can clarify this before I go any further.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当从一种源控制系统切换到另一种源控制系统时,人们经常会发现有许多共同的术语,除了一些“共同”术语实际上在两个系统中具有不同的含义。而且它变得更加令人困惑,因为 git 的分支模型与 SVN 的分支模型有很大不同。 (警告:我的 SVN 有点生疏了,所以请随意纠正任何错误。)
工作目录具有相同的含义:它是您签出存储库的目录(或者您在其中查看存储库的目录)创建了一个本地存储库),以及您直接使用的文件所在的位置。然而,SVN 所说的“签出”(即复制远程存储库的内容并将存储库“链接”到远程存储库)在 git 中称为“克隆”。在 git 中,签出意味着切换到另一个分支或修订版。
在 SVN 中,分支的工作原理是将整个存储库“复制”到另一个文件夹(在服务器上),并且在本地,您可以检出分支(如果需要,可以检出到另一个工作目录)。所以从某种意义上说,分支本身就是一个完整的存储库。
在 git 中,只有一个存储库,其中包含整个开发历史作为修订的非循环图。一个修订版有一个或两个父修订版,并且给定一个修订版,任意数量的修订版都可以将其作为父修订版(如此多的修订版可以从一个修订版分支出来,并且一个修订版可以是两个修订版序列的合并)。您可以随时签出特定修订版。此操作将使工作目录内容等于指定修订时的内容(换句话说,它将“重播”从初始修订到指定修订的所有修订)。
那么 git 中的分支是什么?它只是附加到修订版上的标签。如果您签出一个分支,您将获得与直接签出分支修订版相同的效果,但是当您提交时,标签将自动前进到新修订版。
最后:在SVN中,HEAD指的是“主”分支;在git中,它指的是您当前签出的提交或分支。
When switching from one source control system to another, one often finds that there are many terms in common, except that some "common" terms actually have different meanings in the two systems. And it becomes even more confusing because git's branching model is quite different from that of SVN. (Warning: my SVN is getting a little rusty, so feel free to correct any errors.)
Working directory has the same meaning: it is the directory where you checked out the repository (or the one where you created a local repo), and where the files you directly work with reside. However, what SVN calls checking out (namely, copying the contents of a remote repository and "linking" your repository to the remote one) is called cloning in git. In git, checking out means to switch to another branch or revision.
In SVN, branching works by "copying" the entire repository to another folder (on the server), and locally, you can checkout the branch (into another working directory, if you want to). So in a sense, a branch is a full repository on its own.
In git, there is only one repository, which contains the entire development history as an acyclic graph of revisions. A revision has one or two parents, and given a revision, any number of revisions may have it as a parent (so many revisions can branch out from one revision, and a revision may be a merge of two revision sequences). At any point in time, you may checkout a specific revision. This operation will make the working directory contents equal to what they were at the time of the specified revision (in other words, it will "replay" all revisions from the initial revision up to the specified one).
What is a branch in git, then? It is simply a label that is attached to a revision. If you check out a branch, you get the effect same effect as if you had directly checked out the branch' revision, but when you commit, the label will automatically move forward to the new revision.
Finally: In SVN, HEAD refers to the "main" branch; in git, it refers to the commit or branch that you have currently checked out.
对您的问题的简短回答:
git checkout
用于在分支之间切换,A slightly shorter answer to your questions:
git checkout
is used to switch between branchesSubversion 在您的工作副本中散布着(隐藏的)“.svn”文件夹,其中包含元数据和结账原始数据的副本。 Git 将其数据放入项目根目录下的单个“.git”文件夹中。
如果您使用 git init 创建一个新的 git 存储库,您应该能够使用 ls -al 命令行魔法看到这个“.git”文件夹(我确信 Mac OS也允许以图形方式实现这一点)。
几乎您使用 git 执行的所有操作(除了 fetch、pull、pull)都使用隐藏在“.git”文件夹中的本地存储库。这就是 git 如此之快的原因之一。如果您从另一个存储库克隆,您将首先在本地提交更改,然后将它们(在您喜欢的任何时候)推送回“源”。
Subversion litters your working copy with (hidden) '.svn' folders, which contain metadata and copies of the original data of the checkout. Git puts it's data into a single '.git' folder at the project root.
If you create a new git repository with
git init
, you should be able to see this '.git' folder withls -al
commandline magic (I'm sure Mac OS allows this graphically, too).Pretty much everything you do with git (except fetch, pull, pull) uses the local repository hidden in the '.git' folder. That's one of the reasons, that makes git so fast. If you had cloned from another repository, you would first commit your changes locally and then push them (at any point you like) back to the 'origin'.