简体   繁体   English

如何将现有Java项目添加到Git存储库

[英]How to add an Existing Java Project to Git repository

I am trying to add an existing Java project from a workspace to my git repository. 我正在尝试将现有的Java项目从工作区添加到我的git存储库。

I'm using git version 1.8.3.2 on Linux. 我在Linux上使用git版本1.8.3.2。

I use this command: 我用这个命令:

git init/committed/remote origin/pushed

However, the src directory is only appearing as a greyed out empty folder. 但是,src目录仅显示为灰色的空文件夹。

How do I add a folder with subfolders to my github repository? 如何将包含子文件夹的文件夹添加到我的github存储库?

This is what it looks like. 这就是它的样子。 Notice 'src' is greyed out and un-clickable. 注意'src'是灰色的,不可点击的。

在此输入图像描述

src and bin are git submodules . srcbingit submodules They're not browsable because they are only pointers to other git repositories - they're not really "folders". 它们不可浏览,因为它们只是指向其他git存储库的指针 - 它们不是真正的“文件夹”。

To add everything in a directory and subdirectories to git in one command, you can use git add . 要将目录和子目录中的所有内容添加到一个命令中的git,您可以使用git add . , which recursively adds . 递归地添加

Section 6 of the Pro Git book explains what a submodule is. Pro Git书的第6节解释了子模块是什么。

Assuming you do not want submodules, you can fix your repository like this: 假设您不想要子模块,您可以像这样修复您的存储库:

cd <project> # Go to the projects root
rm -rf .git  # Remove all git information (keeping your code). 
cd src       # and repeat for src and bin
rm -rf .git
cd ../bin
rm -rf .git
cd ..        # now, back in the projects root
git init     # Make a git repository
git add .    # Add everything to it
git commit -m 'Initial commit'
git remote add github <github-url>
git push -f github # Force push to github, to overwrite everything we had before. 

Note that this will destroy the git repos in src and bin !! 请注意,这将破坏srcbin的git repos !!

I'm pretty sure this is what you want to do. 确定这就是你想要做的。

To add *.* files and folders do it as follow: 要添加*.*文件和文件夹,请执行以下操作:

  1. Navigate within your terminal/dos window to the the root folder of your project and use the command: 在您的终端/ dos窗口中导航到项目的根文件夹并使用以下命令:

git init git init

git add . git add。

git commit -m "This is my commit" git commit -m“这是我的提交”

git push origin master git push origin master

BTW: you can find more simplified details in the following tutorial: Import an existing, unversioned code project to an empty repository 顺便说一句:您可以在以下教程中找到更多简化的详细信息: 将现有的无版本代码项目导入空存储库

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

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