git clone git仓库地址
git clone git仓库地址 文件夹名
git clone -b 分支名 git仓库地址 文件夹名
git config --list
查看配置
git config --list --global
查看全局配置
git config --list --local
查看本地配置(本地配置优先于全局配置)
git branch
查看本地分支
git branch -a
查看远程分支
git log
查看当前分支提交历史
git log --oneline
查看单行的简洁历史
git log --oneline -n4
查看最近的四条简洁历史
git log --all
查看所有分支的提交历史
git log --all --graph
查看图形化的历史
git log --oneline --all -n4 --graph
查看所有分支最近 4 条单行的图形化历史
git shortlog
查看简洁日志(按 提交者 分组)
git diff
查看当前所以文件和暂存区文件差异
git diff 文件名
查看目标文件和暂存区的差异
git status
查看当前本地分支状态
git branch 分支名
新建分支
git checkout 分支名
切换分支
git checkout -b 分支名
创建并切换分支
git fetch origin 分支名:分支名
拉取远程分支
git add 文件名
添加目标文件
git add .
添加当前所有改动的文件
git add ."后缀名"
添加所有该后缀的文件
git add 文件路径
添加所有该路径下的文件
git checkout .
放弃所有当前修改
git commit -m"备注"
提交更改,添加备注
git commit --amend
修改上次提交的commit信息(进入编辑模式)
git commit --amend -m "修改的commit信息"
直接修改上次提交的commit信息
git reset commit号
回退到当前commit
git pull origin 远程分支名:本地分支名
拉取远程分支到本地
git push origin 本地分支名:远程分支名
推送本地分支到远程
git checkout -b 分支名 origin/分支名
在本地有分支的情况下拉取远程的新分支
git branch -d 分支名
删除本地分支
git branch -D 分支名
强制删除本地分支
git commit --amend
修改最后一条commit信息
回退远程提交:
git reset <commitId>
git checkout .
git push origin <branch>:<branch> --force
删除远程分支:
git branch -r -d origin/分支名
git push origin [空格]:分支名
修改远程git地址:
git remote rm origin
git remote add origin 地址
Tag相关:
git tag <tagName>
创建本地Tag
git push origin <tagName>
推送Tag到远程仓库
git tag -d <tagName>
删除本地Tag
git push origin :refs/tags/<tagName>
删除远程Tag
可用来暂存当前正在进行的工作, 比如:
git stash
git stash pop
master切出分支做修改,然后合入master中
master
/
C0 ---- C1 ---- C2 ---- C4
\
C3 ---- C5
\
debugdev
master切出分支做修改,master同时也在修改,然后合入master中
master
/
C0 ---- C1 ---- C2 ---- C4 ---- C6
\ /
C3 ----C5
\
debugdev
git checkout master
git merge debugdev
! [已拒绝] dev -> dev (非快进式)
8581983..c371323 dev -> origin/dev
git fetch origin dev
获取远程dev分支的修改
git merge origin dev
合并远程dev分支
git pull origin dev
更新本地的代码
打开终端
键入命令 ~ » ssh-keygen -t rsa -C "youremail@example.com"
一路回车。当问询到是否覆盖时,键入 y 回车
秘钥生成位置在 ~/.ssh/id_rsa.pub
内
可以用 cat 命令方便复制出来 ~/.ssh » cat ./id_rsa.pub
将该 SSH Key 加入到配置到你的服务器中:github 或 gitlib
步骤中 » 前是执行命令的位置,不是命令内容;id_rsa为私钥,请妥善保管。
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for gitlab.xx.com has changed,
and the key for the corresponding IP address xx.xx.xx.xx
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Please contact your system administrator.
Add correct host key in /xx/xx/.ssh/known_hosts to get rid of this message.
Offending RSA key in /xx/xx/.ssh/known_hosts:9
RSA host key for gitlab.xx.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
known_hosts 文件位置:~/.ssh/known_hosts
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:YGXpYu6n0YD/0fLpD/3rJ+hiLqTzyr3G3nz7cSxsjeY.
Please contact your system administrator.
Add correct host key in /Users/zhaoyidong/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/zhaoyidong/.ssh/known_hosts:8
ECDSA host key for cn.sf.rtc.openfin.com has changed and you have requested strict checking.
Host key verification failed.
执行 ssh-keygen -R + host