<>:根据自己的实景情况,去动态填写对应的内容,比如<branch name> 是分支名字,<url>是你自己用到的url,可能是ssh、http的,等等
| Command | Description |
|---|---|
| git push origin --delete <branch name> | 删除远程分支 |
| git branch -d <branch name> | 删除本地分支 |
| git reset --soft HEAD^ | 撤销commit,不撤销git add.,不删除改动代码 |
| git reset --mixed HEAD^ | 撤销commit,撤销git add.,不删除改动代码 |
| git reset --hard HEAD^ | 撤销commit,撤销git add.,删除改动代码,这个操作就是恢复到上次commit的状态 |
| git reset --hard <commit id> | 在本地仓库回退到指定版本 |
| git push -f origin <branch name> | 强制推送内容到远程仓库(远程仓库的回退,先要本地仓库的版本回退 |
| git reset --<options> HEAD~n | options(soft, mixed, hard), n回退的次数, 这个command意思是撤回n个版本 |
| git cherry-pick <commit id> | 合并某个分支上的单个commit |
| git commit --amend | 修改本次commit的注释,进入编辑vim状态,wq,q,q! |
| git log --pretty=oneline | 漂亮的线性打印日志 |
| git reflog | 查看commit历史,确定回到未来的哪个版本 |
| git checkout <branch name> | 切换到指定分支 |
| git checkout -b <branch name> | 创建指定分支,并且切换过去 |
| git reset | 撤销所有的add文件 |
| git reset + 文件名 | 撤销某个文件的add提交 |
| git remote --verbose / git remote -v | 查看远程仓库仓库的连接地址 |
| git remote remove origin | 删除远程仓库地址 |
| git remote add origin <url> | 添加远程仓库地址 |
| git remote set-url origin <url> | 修改远程仓库地址,使用这个命令是远程仓库origin已被添加,未被添加不能正确设置 |
| git config --global user.name | 查看用户名 |
| git config --global user.email | 查看用户邮箱 |
| git config --global user.name <your name> | 设置或修改用户名 |
| git config --global user.email <your email> | 设置或修改用户邮箱 |
| git revert <commit id> | 还原某次commit的修改(根据情况决定是否用它回退代码) |
| git stash | 隐藏当前更改,工作区和暂存区 |
| git stash pop | 恢复最新的工作进度到工作区(会把工作区和暂存区的文件都恢复到工作区) |
| git cherry-pick <commit id> | 在某个分支和并特定的一个commit |
pull/push 不需要每次输入userName 和 password的操作
- 每次我们从git上拉去代码,git就是服务器,拉取代码的就是客服端;
- 可以把客户端的公钥(id_rsa.pub),粘贴到git上,采用ssh这种克隆方式,这样每次拉去/推送代码的时候就不需要输入userName和password;
- 如果你已经用http这种方式克隆代码了,没有关系,采用git remote set-url origin <url>,url改为ssh的url,就修改好了
id_rsa.pub
- 查看是否公钥已经存在, cat ~/.ssh/id_rsa.pub,如果不存在生成公钥,如果存在,复制并黏贴公钥到git上
- 生成公钥,ssh-keygen,一顿敲回车,然后复制公钥黏贴到git上就好了