Git 拒绝将新项目提交到 GitHub
我尽一切可能
这不是 1 个特定错误,似乎有多个错误
我需要键入哪些命令才能进行此提交?
这是控制台打印输出,为互联网编辑
D:>cd D:ProjectsTestProject
D:ProjectsTestProject>git init
Initialized empty Git repository in D:/Projects/TestProject/.git/
D:ProjectsTestProject>git add .
D:ProjectsTestProject>git commit -m "First Commit"
[master (root-commit) 525f262] First Commit
17 files changed, 976 insertions(+)
create mode 100644 TestProject.sln
create mode 100644 TestProject/App.config
create mode 100644 TestProject/Form1.Designer.cs
create mode 100644 TestProject/Form1.cs
create mode 100644 TestProject/Form1.resx
create mode 100644 TestProject/Properties/AssemblyInfo.cs
create mode 100644 TestProject/Properties/Resources.Designer.cs
create mode 100644 TestProject/Properties/Resources.resx
create mode 100644 TestProject/Properties/Settings.Designer.cs
create mode 100644 TestProject/Properties/Settings.settings
D:ProjectsTestProject>git remote add origin https://github.com/TestAccount/TestProject
D:ProjectsTestProject>git remote -v
origin https://github.com/TestAccount/TestProject (fetch)
origin https://github.com/TestAccount/TestProject (push)
D:ProjectsTestProject>git push origin master
To https://github.com/TestAccount/TestProject
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/TestAccount/TestProject'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
第一次失败的推送,按照指示git pull
D:ProjectsTestProject>git pull
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/TestAccount/TestProject
* [new branch] master -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
D:ProjectsTestProject>git push origin master
To https://github.com/TestAccount/TestProject
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/TestAccount/TestProject'
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.
D:ProjectsTestProject>git pull --rebase
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
D:ProjectsTestProject>git status
On branch master
nothing to commit, working tree clean
D:ProjectsTestProject>git branch
* master
D:ProjectsTestProject>git pull origin master
From https://github.com/TestAccount/TestProject
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
D:ProjectsTestProject>git branch --set-upstream-to=origin/master master
Branch 'master' set up to track remote branch 'master' from 'origin'.
D:ProjectsTestProject>git pull
fatal: refusing to merge unrelated histories
已将添加的文件移出目录
D:ProjectsTestProject>git clone https://github.com/TestAccount/TestProject
Cloning into 'TestProject'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
已将添加的文件移回目录
D:ProjectsTestProject>git add .
D:ProjectsTestProject>git commit -m "Second Commit"
[master 41b46fc] Second Commit
18 files changed, 2 insertions(+)
create mode 100644 TestProject.sln
create mode 100644 TestProject/App.config
create mode 100644 TestProject/Form1.Designer.cs
create mode 100644 TestProject/Form1.cs
create mode 100644 TestProject/Form1.resx
create mode 100644 TestProject/Properties/AssemblyInfo.cs
create mode 100644 TestProject/Properties/Resources.Designer.cs
create mode 100644 TestProject/Properties/Resources.resx
create mode 100644 TestProject/Properties/Settings.Designer.cs
create mode 100644 TestProject/Properties/Settings.settings
create mode 100644 TestProject/README.md
D:ProjectsTestProject>git push
To https://github.com/TestAccount/TestProject
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/TestAccount/TestProject'
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.
D:ProjectsTestProject>git pull
fatal: refusing to merge unrelated histories
修复
git pull origin master --allow-unrelated-histories
git merge origin origin/master