git 工作目录在哪里?

发布于 2024-10-21 14:50:21 字数 418 浏览 1 评论 0原文

各位编码员,今天是我第一次在 Mac 上使用 Tower 深入研究 git - 人生苦短,不能乱搞命令行;)

我确实阅读了一些介绍和教程,但没有一个解决我正在写的问题。我在理解 git 与 SVN 中的工作目录概念时遇到一些困难。

我做了什么:

  1. 我创建了一个本地存储库并将其指向我的项目文件所在的文件夹。
  2. 添加并提交了文件夹中的所有文件。
  3. 编辑了一个文件。显示为已修改。
  4. 添加并提交文件。

这些步骤奏效了。

到目前为止,我还没有被要求提供工作目录的位置,并且我无法签出主 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:

  1. I created a local repo and pointed it to the folder where my project files are.
  2. Added and committed all the files in the folder.
  3. Edited a file. Showed up as modified.
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

痴意少年 2024-10-28 14:50:21

当从一种源控制系统切换到另一种源控制系统时,人们经常会发现有许多共同的术语,除了一些“共同”术语实际上在两个系统中具有不同的含义。而且它变得更加令人困惑,因为 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.

稚气少女 2024-10-28 14:50:21

对您的问题的简短回答:

  • 是的,您的原始文件夹充当当前分支的工作目录,
  • 没有您可能习惯的签出命令;相反,git checkout 用于在分支之间切换,
  • 您可以切换到默认创建的 master 分支 - 与 SVN 相比,这将是头(但它不是称为头)

A slightly shorter answer to your questions:

  • yes, your original folder acts as the working directory for the current branch
  • there's no checkout command as you may be used to; instead git checkout is used to switch between branches
  • you can switch to the master branch which is the one created by default - this would be the head compared to SVN (but it's not called HEAD)
他不在意 2024-10-28 14:50:21

Subversion 在您的工作副本中散布着(隐藏的)“.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 with ls -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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文