Windows上的Git:我的文件在哪里? [英] Git on Windows: Where are my files?

查看:395
本文介绍了Windows上的Git:我的文件在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

警告:我是新来的!



我在本地机器上安装了git。我也将它安装在我们网络上的服务器上。在服务器上,我创建了 C:\ git 来存放我的代码并共享该目录。所以,我做了:

  $ cd C:\ git 
$ git init --bare

我在本地机器上设置了一个新的远程指向git server的共享目录

  $ git remote add shared// shared / path / to / git / folder
$ cd C:\path \to\my\source\code
$ git init
$ git add -A
$ git commit -m初始推送
$ git push shared master
$ git checkout -b test
$ git push shared test

所以,现在我已经完成了所有这些工作,当我回到服务器时,我期待在那里看到我的源代码的服务器副本,但我没有看到它。我是否错过了git的全部内容,或者我做错了什么?

解决方案

Git将源代码存储为二进制大对象 (BLOB或简称为对象)。一个裸仓库,就像服务器上的库一样,只包含那些BLOB,而不是一个工作树,这是你的克隆版本库所具有的,这就是为什么你不能在服务器上看到你的文件是正常的。他们在那里,根据他们的内容进行唯一命名,在 objects 目录中。试试这个实验:

  git init 

echohello> hello.txt

git add hello.txt

dir .git / objects

您将看到名为 2a 的子目录。查看该目录中的内容:

  dir .git / objects / 2a 

您会看到一个名为 93d00994fbd8c484f38b0423b7c42e87a55d48 的文件。目录名称( 2a )以及文件名构成文件 hello.txt的内容的SHA1哈希(字符串hello,即是)。



现在,如果您输入:

  git cat-file -p 2a93d00994fbd8c484f38b0423b7c42e87a55d48 

会看到 hello.txt 的内容!这是将存储在裸存储库中的对象,这就是为什么你不只看到坐在那里的文件 hello.txt ;它被赋予了一个特殊的名字,并被压缩并放入 objects 目录中。



随着资源库的增长,稍微复杂一些,因为随着内容大小和提交数量的增加,Git开始将类似的文件打包在一起;所有的信息仍然存在,但为了提高效率,它会进一步压缩。



另一种方式可以让你自己确信你的文件确实存储在你的服务器上,你可以创建另一个克隆(不是一个纯粹的!),你将有一个工作树,其中包含所有的文件。


WARNING: I'M NEW TO GIT!!

I installed git on my local machine. I also installed it on a server on our network. On the server, I created C:\git to house my code and shared that directory. So, I did:

$cd C:\git
$git init --bare

I set up a new remote on my local machine to point to the shared directory of the "git server"

$git remote add shared "//shared/path/to/git/folder"
$cd C:\path\to\my\source\code
$git init
$git add -A
$git commit -m "initial push"
$git push shared master
$git checkout -b test
$git push shared test

So, now that I've done all that, when I go back to the server, I am expecting to see the server copies of my source code there, but I don't see it. Am I missing the entire point of git or am I doing something wrong?

解决方案

Git stores your source as "binary large objects" (BLOBs, or just "objects" for short). A bare repository, like the one on your server, contains ONLY those BLOBs, not a "working tree", which is what your cloned repository has, which is why you can't see your files as normal on the server. They're there, uniquely named based on their content, in the objects directory. Try this experiment:

git init

echo "hello" > hello.txt

git add hello.txt

dir .git/objects

You'll see a subdirectory called 2a. Look inside that directory:

dir .git/objects/2a

You'll see a file called 93d00994fbd8c484f38b0423b7c42e87a55d48. The directory name (2a) along with the filename make up the SHA1 hash of the contents of the file hello.txt (the string "hello", that is).

Now if you type:

git cat-file -p 2a93d00994fbd8c484f38b0423b7c42e87a55d48

You'll see the contents of hello.txt! That's the object that'll be stored in the bare repository, which is why you don't just see the file hello.txt sitting there; it's been given a special name, compressed, and put in the objects directory.

As your repository grows, things get a little more complicated, because as the size of your content, and the number of your commits grow, Git starts packing similar files together; all of the information is still there, but it's further compressed for efficiency.

Another way you can reassure yourself that your files are indeed being stored on your server, you can create another clone (not a bare one!) and you'll have a working tree with all of your files in it.

这篇关于Windows上的Git:我的文件在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆