Java 将本地工作区签入新的git repo

Java 将本地工作区签入新的git repo,java,eclipse,git,github,Java,Eclipse,Git,Github,我有一个本地工作区,我想保存在git中,直到现在这还不是一个本地git repo。只是工作区 我在git bash中执行的步骤 cd myworkspace git初始化 git添加 git提交-m“首次提交” git远程添加源 git推送源主机 warning: no common commits remote: Counting objects: 4, done. remote: Compressing objects: 100% (3/3), done. remote: Total 4 (

我有一个本地工作区,我想保存在git中,直到现在这还不是一个本地git repo。只是工作区 我在git bash中执行的步骤

cd myworkspace

git初始化

git添加

git提交-m“首次提交”

git远程添加源

git推送源主机

warning: no common commits
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/koushikpaul1/eclipse
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories
这样做我犯了一个错误

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/username/eclipse.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
然后我做了这个

git拉源主机

warning: no common commits
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/koushikpaul1/eclipse
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories
任何人都可以帮我解决这个错误

注意:我创建了一个java版的git repo,所以目前它只有 .gitignore和README.md

在谷歌搜索时,我发现将现有工作区签入git的步骤如下

$cd my_项目

$git init

$git添加*

$git commit-m“首次提交”

$git远程添加源

$git拉原点主控

warning: no common commits
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/koushikpaul1/eclipse
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories
$git推送原始主机

warning: no common commits
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/koushikpaul1/eclipse
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories
但我被困在最后的第二步


非常感谢

这里的问题是您已经在本地工作区中初始化了存储库,其中已经包含了一些文件。当您在GitHub上创建存储库并使用.gitignore和README.md初始化它时,它还包含一些文件

当您推送项目时,git将拒绝,因为它不知道如何合并您的内容

这里有一些解决方案

  • 使用gitpush-f,它将把所有本地存储库推送到远程存储库,但这也将替换.gitignore和README.md,然后您可以稍后手动将它们删除
  • 删除远程git存储库并将其重新设置为裸存储库(不要使用.gitignore、README.md检查init),然后再次尝试推送
  • 只需将远程存储库克隆到本地工作区,然后手动将文件添加到克隆的存储库中
  • 欲了解更多信息,请访问:

    见第5条

    有许多可选项可供您预先填充 具有的存储库如果要将现有存储库导入GitHub, 不要选择这些选项中的任何一个,因为可能会引入合并 冲突。您可以选择从命令行添加这些文件 稍后

    您可以创建自述文件,它是描述项目的文档。 您可以创建一个.gitignore文件,它是一组忽略规则

    您可以选择为项目添加软件许可证


    您是否尝试从URL或源代码中提取?打开git配置,检查源代码是否确实是您正在使用的URL…在您正确指出原因后,解决方案变得简单,非常感谢。工作得很有魅力。另一个帮助是,当我使用gitbash时,gitignore可以完美地工作,但在使用eclipse git插件时,即使我在[eclipse]中添加了模式: