将暂存文件的提交到本地仓库
G:\C\Test1>git commit -m "first commit"
On branch master
Initial commit
Untracked files:
.vscode/
DataStructure/
file/
test.code-workspace
test1.c
test1.exe
nothing added to commit but untracked files present
这些都是没有暂存的,所以无法提交
将本地的文件上传到远端
G:\C\Test1>git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/WhlckCat/LearnC'
这是因为本地的仓库啥都没有,所以无法push
G:\C\Test1>git push -u origin master
To https://github.com/WhlckCat/LearnC
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/WhlckCat/LearnC'
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.
这是因为远端和本地的不匹配,需要先pull一下
git pull origin master
G:\C\Test1>git pull origin master
From https://github.com/WhlckCat/LearnC
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
这是因为远端认为本地的仓库和自己无关,所以需要强行关联一下
git pull origin master --allow-unrelated-histories
本文详细介绍了使用Git进行代码提交的流程,包括解决未暂存文件的问题,处理本地与远程仓库不匹配的情况,以及如何在远端认为本地仓库无关时进行强行关联。通过具体操作步骤,读者可以学习到如何正确地使用Git管理项目。
1218

被折叠的 条评论
为什么被折叠?



