GIT 提交代码到远程仓库

概述

Git是什么?
Git是目前世界上最先进的分布式版本控制系统(没有之一)。
Git有什么特点?简单来说就是:高端大气上档次!

操作流程

1、初始化本地仓库

git init

2、克隆远程仓库代码

git clone https://gitee.com/zyzp/QT-SerialPort.git

3、添加代码到仓库

cd //
git add .

4、提交代码

$ git commit -m "提交代码"

应答

[master 8d9b521] 提交代码
 6 files changed, 982 insertions(+)
 create mode 100644 QT-SerialPort/MyApp.pro
 create mode 100644 QT-SerialPort/MyApp.pro.user
 create mode 100644 QT-SerialPort/main.cpp
 create mode 100644 QT-SerialPort/mainwindow.cpp
 create mode 100644 QT-SerialPort/mainwindow.h
 create mode 100644 QT-SerialPort/mainwindow.ui

5、推送代码 注意,此处需要输入账号密码

git push

应答

Username for 'https://gitee.com': 2584532475@qq.com
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 4 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 6.39 KiB | 1.28 MiB/s, done.
Total 9 (delta 0), reused 0 (delta 0)
remote: Powered By Gitee.com
To https://gitee.com/zyzp/QT-SerialPort.git
   dc07cde..8d9b521  master -> master

错误处理

$ git push
To https://gitee.com/JZ_GSL_UT_WARTER/Firmware.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/JZ_GSL_UT_WARTER/Firmware.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.

出现上述错误的解决方案 git pull

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'Administrator@JAID41T83RF13OD.(none)')

解决方案– 配置全局用户名和邮箱

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

错误

On branch master
Your branch is ahead of 'origin/master' by 12 commits.
  (use "git push" to publish your local commits)

Changes not staged for commit:

解决办法

git reset --hard HEAD~2
如果这篇文章对您很有帮助,不妨
----- 本文结束 ❤ 感谢您的阅读 ----