简体   繁体   English

无法将我的源代码链接到git存储库

[英]Trouble linking my source code to git repository

I'm using Git 1.7.4.1 on Mac 10.6.6. 我在Mac 10.6.6上使用Git 1.7.4.1。 I want to commit my existing project to a repository that was just created. 我想将现有项目提交到刚刚创建的存储库中。 However, when I'm in the directory where my project is located, I get this error ... 但是,当我在项目所在的目录中时,出现此错误...

git clone http://dalvarado@mydomain.com/socialmediaproxy.git
fatal: destination path 'socialmediaproxy' already exists and is not an empty directory.

This is true, but the directory "socialmediaproxy" is what I want to put in my repository. 的确如此,但是目录“ socialmediaproxy”是我要放入存储库中的目录。 How do I do this? 我该怎么做呢?

Thanks, - Dave 谢谢-戴夫

You say that the remote repository was newly created, so I assume that it has no commits in it yet. 您说远程存储库是新创建的,因此我假设它尚未包含任何提交。 I'm also assuming that your existing directory is not under the control of git yet. 我还假设您现有的目录尚未处于git的控制之下。 If those assumptions are true, you could take the following steps: 如果这些假设是正确的,则可以采取以下步骤:

  1. cd socialmediaproxy
  2. git init to initialize this directory as a git repository with a working tree. git init将此目录初始化为带有工作树的git存储库。 That will create a .git directory in socialmediaproxy which will store all the history of your repository. 这将在socialmediaproxy创建一个.git目录,该目录将存储您存储库的所有历史记录。
  3. git add . to stage all the files in that directory for the first version of the project in that repository. 为该存储库中项目的第一个版本暂存该目录中的所有文件。 If there are generated files in that directory, you should be more careful, just adding the files that you want in the repository, and ignoring the others by creating a .gitignore file. 如果该目录中生成了文件,则应更加小心,只需在存储库中添加所需的文件,然后通过创建.gitignore文件来忽略其他文件。
  4. git commit -m "First version of the socialmediaproxy project" to create the first commit in your repository. git commit -m "First version of the socialmediaproxy project"以在存储库中创建第一个提交。
  5. git remote add origin http://dalvarado@mydomain.com/socialmediaproxy.git to set up a "remote" called origin to point to the remote repository. git remote add origin http://dalvarado@mydomain.com/socialmediaproxy.git来设置一个名为origin的“远程”以指向远程存储库。 ("Remotes" are essentially just convenient nicknames for other repositories.) (“ Remotes”本质上只是其他存储库的方便昵称。)
  6. git push -u origin master to push your only commit on the master branch to the remote repository. git push -u origin master将您在master分支上的唯一提交推送到远程存储库。 The -u option says to associate the branch master in the origin repository as the "upstream" repository of your master branch. -u选项表示将origin存储库中的分支mastermaster分支的“上游”存储库相关联。 This enables various helpful defaults in git and produces more helpful output from git status and other commands. 这将在git启用各种有用的默认值,并从git status和其他命令中产生更多有用的输出。

git clone is for creating a new repository from an existing one. git clone用于从现有仓库创建一个新仓库。

You want to fetch from socialmediaproxy: 您想从socialmediaproxy获取:

git remote add origin http://dalvarado@mydomain.com/socialmediaproxy.git
git fetch origin
git checkout master

Either that, or you could just remove the new repository you just created and re-create it as a clone (like you tried to do). 要么,要么就删除刚创建的新存储库,然后将其作为克隆重新创建(就像您尝试做的那样)。 There is no reason to create an empty repository if you want it to be a clone of another repository. 如果您希望它是另一个存储库的副本,则没有理由创建一个空的存储库。

删除您拥有的socialmediaproxy目录,因为克隆将为您创建目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM