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

标签 java linux git github

我正在尝试将工作区中的现有 Java 项目添加到我的 git 存储库。

我在 Linux 上使用 git 版本 1.8.3.2。

我使用这个命令:

git init/committed/remote origin/pushed

但是,src 目录只显示为一个灰色的空文件夹。

如何将包含子文件夹的文件夹添加到我的 github 存储库?

这就是它的样子。请注意,“src”呈灰色且不可点击。

enter image description here

最佳答案

srcbingit 子模块。它们不可浏览,因为它们只是指向其他 git 存储库的指针——它们并不是真正的“文件夹”。

要在一个命令中将目录和子目录中的所有内容添加到 git,您可以使用 git add .recursively adds .

Section 6 of the Pro Git book解释什么是子模块。

假设您不想要子模块,您可以像这样修复您的存储库:

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. 

请注意,这会破坏 srcbin 中的 git repos!!

我很漂亮确定这就是你想要做的。

关于java - 如何将现有的 Java 项目添加到 Git 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18305528/

相关文章:

java - 使用 Freemarker 创建您自己的自定义助手?

python - 如何使用 if 循环使用 python 从 txt 文件中 grep 一个单词?

linux - 缩短进程崩溃和头部射击服务器之间的时间?

javascript - 为 JavaScriptEngine 获取 java ClassNotFoundException

regex - git 提交中的 SLOC

git - 在 windows xp 中安装 gitorious

git - 如何刷新Gitlab Web界面

java - 了解 Java 执行器服务

java - StateMachine - 状态变化的操作

java - 如何使用 if/else 语句表示 boolean 表达式?这是正确的吗?