git : clone 没有引入所有文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4391675/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:48:51  来源:igfitidea点击:

git : clone doesn't bring in all the files?

git

提问by g1t

I just created directory called website. This has a couple of images, index.html page etc. I ran : git --bare init --shared=0777

我刚刚创建了名为website. 这有几个图像,index.html 页面等。我跑了:git --bare init --shared=0777

Now, it successfully created an empty shared repo.

现在,它成功创建了一个空的共享存储库。

I now try to clone this project by going into /developers/developer1on my server and running git clone /live/website. I get the following message:

我现在尝试通过进入/developers/developer1我的服务器并运行git clone /live/website. 我收到以下消息:

Initialized empty Git repository in /developer/developer1/website/.git/
warning: You appear to have cloned an empty repository.

I'm running UNIX. When I do a ls, all I see is the .git folder and none of the images/ index.html page have been cloned here. I tried to do:

我正在运行 UNIX。当我执行 a 时ls,我看到的只是 .git 文件夹,这里没有任何图像/ index.html 页面被克隆。我试图做:

git pull /live/website origin
fatal: Couldn't find remote ref origin
fatal: The remote end hung up unexpectedly

git pull /live/website master
fatal: Couldn't find remote ref master
fatal: The remote end hung up unexpectedly

I know I need to be doing originbecause when I do a git remote -v, here's what I get:

我知道我需要做,origin因为当我做 a 时git remote -v,这就是我得到的:

origin  /live/website  (fetch)
origin  /live/website (push)

So in a nutshell, here's what I need help doing:

所以简而言之,这是我需要帮助的事情:

  1. Figure out how to clone all my files from /live/website to /developer1
  2. Be able to make changes to the files locally on developer1 and push those changes back.
  1. 弄清楚如何将我的所有文件从 /live/website 克隆到 /developer1
  2. 能够对 developer1 上的本地文件进行更改并将这些更改推回。

However, since I can't seem to get the files in the first place, I can't really proceed! The major intention is to allow a lot of developers to simultaneously work on the files and push their changes to the main /live/websitedirectory, once they are done.

但是,由于我似乎无法首先获取文件,因此我无法真正进行!主要目的是允许许多开发人员同时处理文件并将他们的更改推送到主/live/website目录,一旦完成。

回答by eckes

You have to do some steps to get files into your repo. Assume you have a server where the bare repo is stored and some workstations where the actual work is done.

您必须执行一些步骤才能将文件放入您的存储库中。假设您有一个存储裸仓库的服务器和一些完成实际工作的工作站。

  1. Initialize the bare repo on your serverlike you wrote:
    git --bare init --shared=0777

  2. Checkout this directory to your workstation1:
    git clone git://server/repo.git

  3. Drop some files into this freshly cloned repo and add them to the track. To add all of them, do a git add .

  4. Commit the added files to the local repository:
    git commit -m 'initial commit'
    Now, the changes (adding files) were stored in the local repository.

  5. Finally, push back the files (assuming you work on branch master) to the server (known as origin):
    git push origin master

  6. Now, do some more local changes and commit them to the local repo as in step 4. When you type git statusnow, it should give you a message like
    Your branch is ahead of origin/whatever by 1 commit

  7. To bring the changes back to the central repo, you can simply type git pushsince you set up the tracking of the branch in step 5.

  1. 像你写的那样在你的服务器上初始化裸仓库:
    git --bare init --shared=0777

  2. 将此目录签出到您的工作站 1
    git clone git://server/repo.git

  3. 将一些文件放入这个新克隆的存储库中并将它们添加到轨道中。要添加所有这些,请执行git add .

  4. 将添加的文件提交到本地存储库:
    git commit -m 'initial commit'
    现在,更改(添加文件)已存储在本地存储库中。

  5. 最后,将文件(假设您在master分支上工作)推回服务器(称为origin):
    git push origin master

  6. 现在,做一些更多的本地更改并将它们提交到本地存储库,如步骤 4 中所示。当你git status现在输入时,它应该给你一条消息
    Your branch is ahead of origin/whatever by 1 commit

  7. 要将更改带回中央存储库,您可以简单地输入,git push因为您在步骤 5 中设置了分支跟踪。

Now, if you do a git clone git://server/repo.gitfrom another machine (e.g. workstation2), you will get the files you just checked in...

现在,如果您git clone git://server/repo.git从另一台机器(例如,workstation2)执行 a ,您将获得您刚刚签入的文件...

That's the general git workflow:

这是一般的 git 工作流程:

  • Get the files from the server (initial: clone, consecutive pull)
  • Do some changes and store them in the local repo (git commit)
  • When the time has come, push back the local commits to the bare repo (git push)
  • 从服务器获取文件(初始:clone,连续pull
  • 做一些更改并将它们存储在本地 repo ( git commit)
  • 时机成熟时,将本地提交推回裸仓库 ( git push)

To get a more detailed explanation, see the section Private Small Teamin the online version of the progit book.

要获得更详细的解释,请参阅progit 书籍在线版本中的Private Small Team部分。

回答by knittl

when you create a repository with git initit starts as an empty repository. you have to add files (git add -- file1 file2 other files) first and then create a commit (git commit -m'initial commit').

当您创建一个存储库时,git init它作为一个空存储库开始。您必须先添加文件 ( git add -- file1 file2 other files),然后创建提交 ( git commit -m'initial commit')。

you should then be able to clone said repository using git cloneand fetch/pull from it

然后,您应该能够克隆所述存储库git clone并从中获取/拉取