我的操作
-
系统信息:windows 10
-
鼠标
右键
单击目标文件夹
(目录 ),出现Git bash here
菜单。 -
鼠标
左键
单击Git bash here
菜单,出现Git 客户端窗口
。 -
git init
-
返回:
Initialized empty Git repository in '文件夹绝对路径'
-
git add .
(半角英文句号) -
无返回
-
git commit -m "学习路线和必备书籍"
-
返回:
[master (root-commit) 3b5e781] 学习路线和必备书籍
8 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 "0-Books/1-Java\346\240\270\345\277\203\346\212\200\346\234\257\345\215\2671-10.pdf.pdf"
create mode 100644 "0-Books/2-Java\346\240\270\345\277\203\346\212\200\346\234\257\345\215\2672-9.pdf"
create mode 100644 "0-Books/3-Java\347\274\226\347\250\213\346\200\235\346\203\263-4.pdf"
create mode 100644 "0-Books/4-Effective\302\240Java-2.pdf"
create mode 100644 "0-Books/5-\346\267\261\345\205\245\347\220\206\350\247\243Java\350\231\232\346\213\237\346\234\272-2.pdf"
create mode 100644 "0-Books/6-Java8\350\231\232\346\213\237\346\234\272\350\247\204\350\214\203.pdf"
create mode 100644 "0-Books/7-Java\350\247\243\346\203\221.pdf"
-
git remote add origin https://github.com/pyjack/Java.git # 添加远程分支
-
无返回信息
-
git push origin master # 进行提交操作
出现报错
报错信息
To https://github.com/pyjack/Java.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/pyjack/Java.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.
报错原因
Github 创建仓库,自动生成了 README.md,相当于在 master 分支进行了一次代码提交操作,但是本地初始化的仓库却没有提交记录,也没有 README.md 文件。
解决办法
参考自 github 报错 failed to push some refs to …
- 执行
git pull --rebase origin master
- 返回
From https://github.com/pyjack/Java
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: 学习路线和必备书籍
目标文件夹下出现 README.md 文件
最后执行
git push -u origin master