Git日常使用手记
创建新的git仓库
git init # 初始化- git add readme.md # 添加新文件
- git commit -am "some description"
- git remote add origin [远端地址] # 添加远端仓库地址
- git push -u origin master # 提交到远端
在新仓库中创建分支
git branch newbranch # 在本地创建分支- git checkout newbranch # 切换到新分支
- git push origin newbranch # 将新分支提交到远端
- git branch -d newbranch # 删除本地分支
- git psuh origin :newbranch # 删除远端分支,分支前的冒号代表删除
操作远端分支
git branch -a # 查看有哪些远端分支- git branch -a # 查看有哪些远端分支,并显示最后一下commit信息
- git push origin --delete [远端分支名称] # 删除指定远端分支
版本回退
git log # 显示提交日志,展示不那么漂亮- git log --pretty=oneline # 查看提交日志,在一行展示,更漂亮
- git reset --hard [commit id] # 通过git log 查看提交历史以确定要回到的位置,并拿到想回到的commit id 执行之
- git reflog # 查看所有执行的git命令 可以用来查找回滚之前的 commit id 在使用git reset --hard 回滚过去