Git 在哪里存储文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3082445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where does Git store files?
提问by Yuval Karmi
I just ran the following commands on my Ruby on Railsproject:
我只是在我的Ruby on Rails项目上运行了以下命令:
git init
git add .
git commit -a -m 'Initial'
Where does Gitactually store this repository? (It's on my local machine, but where?)
Git实际上将这个存储库存储在哪里?(它在我的本地机器上,但在哪里?)
回答by Matthew Flaschen
It will create your repository in the .git
folder in the current directory.
它将.git
在当前目录的文件夹中创建您的存储库。
回答by VonC
To be a bit more complete, Git works with:
为了更完整一点,Git 可以使用:
- the working tree(the root of which being where you made a
git init
) - "path to the Git repository" (where there is a
.git
, which will store the revisions of all your files)
- 在工作树(它的根是在那里你犯了一个
git init
) - “ Git 存储库的路径”(其中有一个
.git
,将存储所有文件的修订版)
GIT_DIR
is an environment variable, which can be an absolute path or relative path to current working directory.
GIT_DIR
是一个环境变量,可以是当前工作目录的绝对路径或相对路径。
If it is not defined, the "path to the git repository" is by default at the root directory of your working tree(again, where you made a git init
).
如果未定义,则“git 存储库的路径”默认位于工作树的根目录(同样,您在其中创建了git init
)。
You can actually execute any Git command from anywhere from your disk, provided you specify the working tree path and the Git repository path:
您实际上可以从磁盘的任何位置执行任何 Git 命令,前提是您指定了工作树路径和 Git 存储库路径:
git command --git-dir=<path> --work-tree=<path>
But if you execute them in one of the subdirectories of a Git repository (with no GIT-DIR or working tree path specified), Git will simply look in the current and parent directories until it find a .git
, assume this it also the root directory of your working tree, and use that .git
as the only container for all the revisions of your files.
但是,如果您在 Git 存储库的子目录之一中执行它们(没有指定 GIT-DIR 或工作树路径),Git 将简单地在当前和父目录中查找.git
,直到找到一个,假设它也是根目录您的工作树,并将其.git
用作所有文件修订版的唯一容器。
Note: .git
is also hidden in Windows (msysgit).
You would have to do a dir /AH
to see it.
git 2.9 (June 2016) allows to configure that.
注意:.git
在 Windows (msysgit) 中也是隐藏的。
你必须做一个dir /AH
才能看到它。
git 2.9(2016 年 6 月)允许配置.
Note that Git 2.18 (Q2 2018) is starting the process to evolve how Git is storing objects, by refactoring the internal global data structure to make it possible to open multiple repositories, work with and then close them.
请注意,Git 2.18(2018 年第二季度)正在启动通过重构内部全局数据结构来改进 Git 存储对象的方式的过程,从而可以打开多个存储库,使用然后关闭它们。
See commit 4a7c05f, commit 1fea63e(23 Mar 2018) by Jonathan Nieder (artagnon
).
See commit bd27f50, commit ec7283e, commit d2607fa, commit a68377b, commit e977fc7, commit e35454f, commit 332295d, commit 2ba0bfd, commit fbe33e2, commit cf78ae4, commit 13068bf, commit 77f012e, commit 0b20903, commit 93d8d1e, commit ca5e6d2, commit cfc62fc, commit 13313fc, commit 9a00580(23 Mar 2018) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
--in commit cf0b179, 11 Apr 2018)
请参阅Jonathan Nieder ( ) 的commit 4a7c05f和commit 1fea63e(2018 年 3 月 23 日)。
见提交bd27f50,提交ec7283e,提交d2607fa,提交a68377b,提交e977fc7,提交e35454f,提交332295d,提交2ba0bfd,提交fbe33e2,提交cf78ae4,提交13068bf,提交77f012e,提交0b20903,提交93d8d1e,提交ca5e6d2,提交cfc62fcartagnon
, commit 13313fc, commit 9a00580(23 Mar 2018) by Stefan Beller ( stefanbeller
)。
(由Junio C gitster
Hamano合并-- --在提交 cf0b179 中,2018 年 4 月 11 日)
repository
: introduce raw object store fieldThe raw object store field will contain any objects needed for access to objects in a given repository.
This patch introduces the raw object store and populates it with the
objectdir
, which used to be part of the repository struct.As the struct gains members, we'll also populate the function to clear the memory for these members.
In a later step, we'll introduce a
struct object_parser
, that will complement the object parsing in a repository struct:
- The raw object parser is the layer that will provide access to raw object content,
while the higher level object parser code will parse raw objects and keeps track of parenthood and other object relationships using '
struct object
'.For now only add the lower level to the repository struct.
repository
: 引入原始对象存储字段原始对象存储字段将包含访问给定存储库中的对象所需的任何对象。
这个补丁引入了原始对象存储并用 填充它
objectdir
,它曾经是存储库结构的一部分。随着结构获得成员,我们还将填充函数以清除这些成员的内存。
在后面的步骤中,我们将引入一个
struct object_parser
, 它将补充存储库结构中的对象解析:
- 原始对象解析器是提供对原始对象内容的访问的层,
而更高级别的对象解析器代码将解析原始对象并使用“
struct object
”跟踪父母身份和其他对象关系。现在只将较低级别添加到存储库结构中。
回答by Vishal Bandre
If you are on an English Windows machine, Git's default storage path will be C:\Documents and Settings\< current_user>\
, because on Windows the default Git local settings resides at C:\Documents and Settings\< current_user>\.git
and so Git creates a separate folder for each repo/clone
at C:\Documents and Settings\< current_user>\
and there are all the directories of cloned project.
如果你使用的是英文的 Windows 机器,Git 的默认存储路径将是C:\Documents and Settings\< current_user>\
,因为在 Windows 上,默认的 Git 本地设置驻留在 at C:\Documents and Settings\< current_user>\.git
,因此 Git 为每个repo/clone
at创建一个单独的文件夹,C:\Documents and Settings\< current_user>\
并且有克隆项目的所有目录。
For example, if you install Symfony2 with
例如,如果您安装Symfony2
git clone git://github.com/symfony/symfony.git
the Symfony directory and file will be at
Symfony 目录和文件将位于
C:\Documents and Settings\< current_user>\symfony\
回答by Brenton Alker
In the root directory of the project there is a hidden .git
directory that contains configuration, the repository etc.
在项目的根目录中有一个隐藏.git
目录,其中包含配置、存储库等。
回答by user2271109
I'm on Windows and found my location by right clicking the Git Bash program in my Start menu and selecting Properties. The Shortcut tab shows the "Start in:" value. For me, it was %HOMEDRIVE%%HOMEPATH%
, so I opened a CMD prompt and typed echo %HOMEDRIVE%%HOMEPATH%
to see the actual location.
我在 Windows 上,通过右键单击开始菜单中的 Git Bash 程序并选择属性来找到我的位置。“快捷方式”选项卡显示“开始于:”值。对我来说,它是%HOMEDRIVE%%HOMEPATH%
,所以我打开了一个 CMD 提示并输入echo %HOMEDRIVE%%HOMEPATH%
以查看实际位置。
回答by Peter Tillemans
In a .git directory in the root of the project. Unlike some other version control systems, notably CVS, there are no additional directories in any of the subdirectories.
在项目根目录的 .git 目录中。不像其他一些版本控制系统,特别是 CVS,在任何子目录中都没有额外的目录。
回答by bouvierr
I also couldn't find my git repository. I am using Windows 8 and created my repository (by mistake) under C:\Program Files (x86)\Git
. I could see the repository folder in bash but not in cmd or Windows Explorer.
我也找不到我的 git 存储库。我正在使用 Windows 8 并在C:\Program Files (x86)\Git
. 我可以在 bash 中看到存储库文件夹,但在 cmd 或 Windows 资源管理器中看不到。
Then I remembered about Windows's "Virtual Store" feature. My repository folder was actually created under C:\Users\<username>\AppData\Local\VirtualStore\Program Files (x86)\Git\<myrepo>
and in there was my .git
folder!
然后我想起了 Windows 的“虚拟商店”功能。我的存储库文件夹实际上是在C:\Users\<username>\AppData\Local\VirtualStore\Program Files (x86)\Git\<myrepo>
我的.git
文件夹下创建的!
回答by Jason Lam
If you are looking for where the project folder was created. I noticed when I typed in the git bash.
如果您正在寻找项目文件夹的创建位置。当我输入 git bash 时,我注意到了。
$ git init projectName
$ git init 项目名称
it will tell me, where the project folder is for that project.
它会告诉我,该项目的项目文件夹在哪里。
回答by Bruce Mubangwa
For me when I run git clone, Git will store the cloned package in the directory that I am running the command from.
对我来说,当我运行 git clone 时,Git 会将克隆的包存储在我运行命令的目录中。
- I use windows.
- 我使用窗户。
for example:
例如:
C:\Users\user>git clone https://github.com/broosaction/aria
will create a folder:
将创建一个文件夹:
C:\Users\user\aria
回答by Shabbar
usually it goes to Documents folder in windows : C:\Users\<"name of user account">\Documents\GitHub
通常它会转到 Windows 中的 Documents 文件夹:C:\Users\<"name of user account">\Documents\GitHub