Git提交代碼及異常處理方法
1.開(kāi)始步驟
- 第一步:首先在gitee.com上創(chuàng)建一個(gè)項(xiàng)目宦搬,與你本地項(xiàng)目同名
- 第二步:在git bash 下操作
① git init 初始化本地倉(cāng)庫(kù)
② git add . 將當(dāng)前文件加入到倉(cāng)庫(kù)
③ git commit -m 'first commit' 第一次提交項(xiàng)目文件
④ git remote add origin https://gitee.com/null_948_8938/ayiol_auth.git 關(guān)聯(lián)遠(yuǎn)程倉(cāng)庫(kù)逗鸣,藍(lán)色為git項(xiàng)目URL
⑤ git push -u origin master 推送遠(yuǎn)程倉(cāng)庫(kù)
2.異常
error: failed to push some refs to 'https://gitee.com/null_948_8938/ayiol_auth.git' 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.
方法:報(bào)錯(cuò)因?yàn)檫h(yuǎn)程倉(cāng)庫(kù)與本地倉(cāng)庫(kù)文件不一致,使用git pull拉下遠(yuǎn)程代碼到本地
git pull
warning: no common commits remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From https://gitee.com/null_948_8938/ayiol_auth * [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
原因:報(bào)錯(cuò)原因是沒(méi)有指定本地master和遠(yuǎn)程origin/master的連接,
執(zhí)行g(shù)it branch --set-upstream master origin/master,設(shè)置鏈接
git branch --set-upstream master origin/master
fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.
原因:
再次執(zhí)行:git pull origin master
fatal: refusing to merge unrelated histories 拒絕合并不相關(guān)的歷史
原因:
報(bào)錯(cuò)原因是本地倉(cāng)庫(kù)與遠(yuǎn)程倉(cāng)庫(kù)不同 解決方案: git添加一句代碼,這句代碼是在git2.9.2版本發(fā)生的益缠,最新版本需要添加 --allow-unrelated-histories,此代碼為忽略不相關(guān)歷史文件 即:git pull origin master --allow-unrelated-histories 重新git push origin master 纤壁,不在報(bào)錯(cuò)左刽,推送完成