简体   繁体   English

将本地工作区检入新的git仓库

[英]check in local workspace into new git repo

I have a local workspace which I want to save in git, this wasnt a local git repo until now.Just workspace The steps I did in git bash 我有一个本地工作区,我想保存在git中,这不是一个本地git repo直到现在。刚工作区我在git bash中做的步骤

cd myworkspace cd myworkspace

git init git init

git add . git add。

git commit -m "First commit" git commit -m“第一次提交”

git remote add origin https://github.com/username/eclipse.git git remote add origin https://github.com/username/eclipse.git

git push origin master git push origin master

By doing this I got an error 通过这样做我得到一个错误

! [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.

then I did this 然后我做了这个

git pull origin master git pull origin master

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

Anyone can help me with this error , 任何人都可以帮我解决这个错误,

Note : I created my git repo as a java one so currently it has only .gitignore and README.md 注意:我创建了我的git repo作为java,所以目前只有.gitignore和README.md

while googling I found the steps to check in an existing workspace into git are 谷歌搜索我发现将现有工作区签入git的步骤是

$ cd my_project $ cd my_project

$ git init $ git init

$ git add * $ git add *

$ git commit -m "First commit" $ git commit -m“第一次提交”

$ git remote add origin https://github.com/yourname/my_project.git $ git remote add origin https://github.com/yourname/my_project.git

$ git pull origin master $ git pull origin master

$ git push origin master $ git push origin master

But I am stuck at the second last step. 但我陷入了倒数第二步。

Many Thanks ! 非常感谢 !

The issue here is you already init repository on your local workspace which already contain some files. 这里的问题是您已经在本地工作区上初始化存储库,该存储库已包含一些文件。 When you create repository on GitHub and init it with .gitignore and README.md it also contain some files. 当您在GitHub上创建存储库并使用.gitignore和README.md初始化它时,它还包含一些文件。

When you push your project git will reject because it does not know how to merge your content. 当您推送项目时,git将拒绝,因为它不知道如何合并您的内容。

Here are solutions 这是解决方案

  1. Use git push -f which will push all your local repository to remote repository but this will also replace .gitignore and README.md, then you can them manually later. 使用git push -f将所有本地存储库送到远程存储库,但这也将替换.gitignore和README.md,然后您可以稍后手动完成。
  2. Delete your remote git repository and reinit it as bare repository (do not check init with .gitignore, README.md) then try to push again. 删除远程git存储库并将其重新启动为裸存储库(不要使用.gitignore,README.md检查init)然后尝试再次推送。
  3. Just clone remote repository to your local workspace then manually add your files to the cloned repository 只需将远程存储库克隆到本地工作区,然后手动将文件添加到克隆的存储库中

For more info visit: https://help.github.com/articles/creating-a-new-repository/ 欲了解更多信息,请访问: https//help.github.com/articles/creating-a-new-repository/

See number 5. 见5号。

There are a number of optional items you can pre-populate your repository with. 您可以使用预先填充存储库的许多可选项。 If you're importing an existing repository to GitHub, don't choose any of these options, as you may introduce a merge conflict. 如果您要将现有存储库导入GitHub,请不要选择任何这些选项,因为您可能会引入合并冲突。 You can choose to add these files from the command line later. 您可以选择稍后从命令行添加这些文件。

You can create a README, which is a document describing your project. 您可以创建README,它是描述项目的文档。 You can create a .gitignore file, which is a set of ignore rules. 您可以创建.gitignore文件,该文件是一组忽略规则。

You can choose to add a software license for your project. 您可以选择为项目添加软件许可证。

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

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