远程新建了仓库,直接将本地的文件上传,先建立连接
宾尼宾尼@xiaoxin MINGW64 /e/code/ssm-Demo (master)
$ git remote -v
origin https://gitee.com/lxy188/spring-ym.git (fetch)
origin https://gitee.com/lxy188/spring-ym.git (push)
查询状态
宾尼宾尼@xiaoxin MINGW64 /e/code/ssm-Demo (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .idea/$PRODUCT_WORKSPACE_FILE$
new file: .idea/compiler.xml
new file: .idea/misc.xml
new file: .idea/uiDesigner.xml
new file: .idea/workspace.xml
new file: demo06-acid/demo06-acid.iml
new file: ssm-Demo.iml
执行添加提交报错 git commit '完成spring源码'
宾尼宾尼@xiaoxin MINGW64 /e/code/ssm-Demo (master)
$ git add .
宾尼宾尼@xiaoxin MINGW64 /e/code/ssm-Demo (master)
$ git commit '完成spring源码'
error: pathspec '完成spring源码' did not match any file(s) known to git
命令错误 git commit -m "first commit"
宾尼宾尼@xiaoxin MINGW64 /e/code/ssm-Demo (master)
$ git commit -m "first commit"
[master d29454b] first commit
8 files changed, 454 insertions(+)
create mode 100644 .idea/$PRODUCT_WORKSPACE_FILE$
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/uiDesigner.xml
create mode 100644 .idea/vcs.xml
create mode 100644 .idea/workspace.xml
create mode 100644 demo06-acid/demo06-acid.iml
create mode 100644 ssm-Demo.iml
进行git push操作时报错:fatal: The current branch master has no upstream branch.
宾尼宾尼@xiaoxin MINGW64 /e/code/ssm-Demo (master)
$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
没有将本地的分支与远程仓库的分支进行关联
通过git branch查看本地分支只有master,通过git branch -a查看远程分支,有master和remotes/origin/master两个
这时由于远程仓库太多,且分支较多。在默认情况下,git push时一般会上传到origin下的master分支上,然而当repository和branch过多,而又没有设置关联时,git就会产生疑问,因为它无法判断你的push目标

使用
git push --set-upstream origin master命令或者
git push -u origin master命令

本地分支和远程当前分支不匹配上,查看当前本地分支,现当前只有master默认分支,而我提交的是到远程的dev分支
新建并切换分支 git checkout -b dev
push到dev分支上

远端仓库有了比你本地分支更新的commit,不允许你的此次修改直接推送到远端分支。
可以通过
fetching and merging或者与其相同作用的pull解决,把远端已更新的项目拉回本地与你的本次修改合并,再push。(git fetch 远程主机名 分支名 上面命令将某个远程主机的某个分支的更新,全部取回本地。)
注意pull前本次修改要提前commit到本地分支上;fetch merge pull的参数都要注意

事实上,如果是两个不同的项目,可能会不允许简单地pull
$ git pull origin master --allow-unrelated-histories
#这条命令允许了不同项目的合并
接下来就可以进行push$ git push origin master

补充其他命令
git log 查看所有的commit提交记录
git show 查看提交的详情
本文主要讲述在使用Git将本地文件上传到远程仓库时遇到的问题及解决办法。包括执行添加提交报错、本地分支与远程分支未关联、本地与远程分支不匹配、远端仓库有更新不允许直接推送等问题,还补充了git log、git show等命令。
2066






