Git的常用命令(二)

工作中我们经常需要对代码进行回滚,本地回滚都很简单,但是远程回滚并不是那么容易。网上的大部分资料写的都很复杂,操作不够简单明了。现总结以下我经常用到的git命令。

关于本地回滚

本地回滚命令:git reset --hard commit节点

关于远程回滚

第一步:进行本地回滚(git reset --hard commit节点);
第二步:推送至远程(git push -f

关于tag

git tag : 查看所有标签
git tag <tagname> commit节点 : 在指定节点新建一个标签
git tag -a <tagname> -m "blablabla..." commit节点 : 在指定节点新建一个标签并指定标签信息
git push origin <tagname> : 推送某个标签到远程
git push origin --tags : 推送全部标签到远程
git tag -d <tagname> :删除本地标签
git push origin :refs/tags/<tagname> : 删除远程标签
git checkout <tagname> : 将代码切换到指定标签处
git show <tagname> : 查看指定标签的详细信息

关于分支

git branch:查看分支
git branch <branchname>:创建分支
git checkout -b <branchname>:创建并切换分支
git branch -d <branchname>:删除分支

常用命令

git add 文件名 :添加文件到暂存区。
git commit -m 提交信息说明 :提交文件到仓库。
git push :将本地代码推送至远程。
git pull :拉取远程代码。
git checkout 分支名称 :切换分支。
git merge 分支名称:合并分支。
gitk :启动图形查看模式。
git status 查看仓库状态。
git log 查看提交历史。
git config --global user.name xxx:设置提交人名称。
git config --global user.email xxx:设置提交人邮箱。


Git更新提交到服务器
git add readme.txt    //可以多个文件,可以是包含多个文件的文件夹
git add . 添加多个文件
git commit -m “追加处理” //-m: 注释 //本命令是提交到本地库
git push //提交到远程服务器库

下载更新
git pull

恢复本地操作
git checkout 文件
git checkout .

显示详细comit log
git log
显示简要操作日志及注释
git reflog

回退
提交到远程库前
git reset  --hard 前七位(例c011eb3)

提交到线上后
git revert 前七位(例c011eb3


作者:tiancai啊呆
链接:https://www.jianshu.com/p/87858d80b9c9
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

猜你喜欢

转载自blog.csdn.net/mrlin6688/article/details/82705664