简体   繁体   English

从现有目录创建git repo

[英]creating git repo from existing dir with content

I have an appengine connected android project, so that the project consists of two directoris: CatProj and CatProj-AppEngine . 我有一个与appengine连接的android项目,因此该项目由两个Directoris组成: CatProjCatProj-AppEngine Instead of having the two in the eclipse /workspace I put them in cats directory. 我没有将它们放在eclipse /workspace而是将它们放在cats目录中。 Anyway, I create a git account and buy micro level so I can save private projects. 无论如何,我创建了一个git帐户并购买了微型帐户,因此我可以保存私人项目。 Now I am following the instructions for putting my code on GitHub. 现在,我按照说明将代码放在GitHub上。 When I do the following command inside my cat directory, I get the following message 当我在cat目录中执行以下命令时,收到以下消息

git init
Initialized empty Git repository in /git_repo/cats/.git/

But the thing is the project is not empty: all the code for the app and server are in the directories. 但问题是项目不是空的:应用程序和服务器的所有代码都在目录中。 The reason I am paying attention to this message is because at the end of the instructions, when I check on github, both directories are there but empty: it does not push the content of CatProj or CatProj-AppEngine . 我关注此消息的原因是,在说明的末尾,当我在github上检查时,两个目录都存在,但为空:它不会推送CatProjCatProj-AppEngine

The steps I followed are https://help.github.com/articles/create-a-repo 我遵循的步骤是https://help.github.com/articles/create-a-repo

git init
git add .
git commit -m 'first commit'
git remote add origin https://github.com/username/cats.git
git push origin master

When the above failed, I replaced . 当以上方法失败时,我更换了. with * but I still get the same problem. *但我仍然遇到相同的问题。 So I am wondering if there is a recursive command to tell git to commit the recursive content of a directory 所以我想知道是否有一个递归命令告诉git提交目录的递归内容

You could check the effect of git add by using: 您可以使用以下命令检查git add的效果:

man git add

git add [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]
             [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]]
             [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing]
             [--] [<pathspec>...]

Also to get some more help on how to use git, i suggest you to check this site: http://rogerdudler.github.io/git-guide/ 另外,要获取有关如何使用git的更多帮助,我建议您检查此站点: http : //rogerdudler.github.io/git-guide/

This should be working.. 这应该工作..

  1. Check whether git is working; 检查git是否正常工作; Try creating test directory and some files with git 尝试使用git创建测试目录和一些文件
  2. Ensure to issue commands from git directory; 确保从git目录发出命令; use command "pwd" 使用命令“ pwd”
  3. Check for your exclude rules in .gitignore and .git/info/exclude; 检查.gitignore和.git / info / exclude中的排除规则; In .git folder 在.git文件夹中

If this is not working try reinstalling git -- or -- use TortoiseGit it is GUI application for git https://tortoisegit.org/download/ 如果这不起作用,请尝试重新安装git-或-使用TortoiseGit它是git的GUI应用程序https://tortoisegit.org/download/

If I understand correctly, you are wondering why git init inside a directory full of files tells you: 如果我理解正确,您想知道为什么在充满文件的目录中的git init告诉您:

Initialized empty Git repository in /git_repo/cats/.git/

The directory where you run the command is called the work tree , which is different from the repository . 运行命令的目录称为工作树 ,它与存储库不同。 Your work tree is full of files. 您的工作树中充满了文件。 But the repository is still empty. 但是存储库仍然是空的。 Until you add files with git add and commit with git commit , the repository is empty. 在使用git add添加文件和使用git commit文件之前,存储库为空。

I'm not sure what error you're talking about at the end of your post. 我不确定您在帖子末尾谈论的是什么错误。 After you commit some revisions to your repository, and push them to GitHub, you should see your files and commits on GitHub. 在对存储库提交一些修订并将其推送到GitHub之后,您应该在GitHub上查看文件和提交。 The steps you wrote above are correct and should work. 您上面编写的步骤是正确的,应该可以运行。 If you get an error message, include it in your post. 如果收到错误消息,请将其包含在您的帖子中。

Btw, it's better to add the -u flag to your initial push, like this: 顺便说一句,最好在初始推送中添加-u标志,如下所示:

git push -u origin master

And for your information, git add . 对于您的信息, git add . and git add * are different, because * normally doesn't include the files starting with a dot. git add *不同,因为*通常不包括以点开头的文件。 git add . will recursively add the current directory (including files starting with . ), and all subdirectories. 将递归添加当前目录(包括以.开头的文件)以及所有子目录。

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

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