您好我是Git的新手,并尝试创建一个本地存储库并提交代码,但当我尝试在我的推送命令上推送代码时,它会出现此错误
SUMITs-Mac-mini:gitupload sumit$ git push -u origin master
To https://github.com/sumittiwari87/First-Gulp-Lesson.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/sumittiwari87/First-Gulp-Lesson.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.
所以我试图提取提交更改并且我得到了错误。
SUMITs-Mac-mini:gitupload sumit$ git pull origin master
warning: no common commits
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/sumittiwari87/First-Gulp-Lesson
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
fatal: refusing to merge unrelated histories
我不明白为什么会这样。
答案 0 :(得分:1)
fatal: refusing to merge unrelated histories
您的分支机构没有历史记录的公共基础提交。默认情况下允许此行为,但通常不是预期的结果(不同的提交)。
进行合并时可以有--allow-unrelated-histories
(默认情况下,pull只是一个fetch + merge,可以配置为进行rebase)。但通常情况并非如此,尤其是你是git的新手(除非你知道这种行为和历史)。
我的建议是查看此存储库的本地和远程历史记录:git log --oneline --decorate --all --graph
。如果您希望获得解释输出的帮助,请随意编辑显示此输出的问题。
答案 1 :(得分:0)
你有没有尝试过git pull并解决你的冲突(如果有的话)然后
git add .
git commit -m "comment"
git push origin master
答案 2 :(得分:-1)
git pull -u origin master。我也可以这样做。 你没有把-u