git 提交命令#
提交步骤#
1. 添加当前目录下的所有文件到暂存区
git add .
2. 显示工作目录和暂存区的状态
git status
3. 将暂存区内容添加到本地仓库
git commit -m "commit info"
4. 指定远程仓库名和分支名
git push origin master
若出现错误
$ git push origin master
To gitee.com:tanggitee/embedded-learning-notes.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'gitee.com:tanggitee/embedded-learning-notes.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.
可以在上面 3 和 4 中增加下面的命令,强制把远程仓库的代码更新到当前分支上面。
git pull --rebase origin master
git 首次推送项目到码云(gitee)#
创建账号#
创建一个 Gitee 账号,Gitee 在国内速度快
本地安装 Git#
前往 Git 根据操作系统下载 Git 到本地
ssh 密钥#
本地生成秘钥#
右击桌面打开你的 git bash 第一次使用 Git 时 需要先生成 ssh
ssh-keygen -t rsa -C "your_email"
生成的秘钥一般在你操作系统用户下的.ssh 目录中
告诉本地系统#
将密钥告诉本地系统
ssh-add ~/.ssh/id_rsa
(此处如果出现Could not open a connection to your authentication agent.
则先执行 ssh-agent bash
)
查看生成的公钥#
cat ~/.ssh/id_rsa.pub
上传公钥#
复制该公钥粘贴到你的Gitee
的SSH
公钥页面
使用SSH
公钥可以让你在你的电脑和码云通讯的时候使用安全连接(Git
的Remote
要使用SSH
地址)
配置 User#
打开git bash
需要配置:
git config --global user.name "your_Name"
git config --global user.email"your_email"
初始化本地 Git 仓库#
git init
这条命令执行完毕后会多出一个.git
文件夹
添加变更文件#
git add . // 表示添加全部变更文件
提交文件#
git commmit -am "message" // 表示提交全部变更文件
添加远程地址#
git remote add origin [email protected]:你的gitee用户名/仓库名.git
ssh 测试#
ssh -T [email protected]
显示Welcome to Gitee.com
, 你的用户名!说明 ssh 正确
可能出现的错误#
如果出现 fatal: remote origin already exists.
则执行 git remote rm origin
首次提交#
第一次提交可能会出现如下错误
error: failed to push some refs to 'https://gitee.com/tomFat/interview.git'
所以需要在提交前执行 git pull
合并两个版本库#
git pull origin master --allow-unrelated-histories
向 Github 或 Gitee 推送#
git push -u origin master
或git push 你的gitee上的仓库名 master # 推送到指定的仓库的master分支
或git push -u origin master -f #强制推送
【Gitee】本地 push 代码成功,但是不计入贡献度贡献值,该怎么处理(已解决 同理 github gitlab)#
这两天因为 gitee、github 相关的一些需求,修改了一些配置,导致本地代码 push 到环境上,但是不计入贡献(格子没亮),这就很纳闷了。通过一顿操作检索解决了此问题,记录一下。
其实是配置信息不对啦,改下你的配置信息即可,如果下面的方法还不能解决你的问题,请继续往下看。
// 查看
git config --global -l
// 设置
git config --global user.name "your-username"
git config --global user.email "[email protected]"
12345
注意,在 Personal Settings 里,Profile 里有个 email,然后下面还有个 Emails 也有个 email,请用 Emails 下面的。
Git 配置级别有以下 3 类:#
1、仓库级别 local 【优先级最高】
2、用户级别 global【优先级次之】
3、系统级别 system【优先级最低】
git config --list 查看所有的配置信息,依次是系统级别、用户级别、仓库级别
Git Config 常用配置选项#
git config -e 编辑配置文件
- git config --local -e 编辑仓库级别配置文件
- git config --global -e 编辑用户级别配置文件
- git config --system -e 编辑系统级别配置文件
git config 修改配置项目
- git config --global user.email “[email protected]”
- git config --global user.name “Your Name”
-
git config 添加配置项目
- git config [--local|--global|--system] --add section.key value
git config 获取配置项目
- git config [--local|--global|--system] --get section.key
git config 删除配置项目
- git config [--local|--global|--system] --unset section.key