git使用命令速查

/**本地操作**/


1. git init //初始化项目


2. git add 文件名 //添加文件到暂存区


3. git commit //提交文件到仓库


4. git status //查看是否还有文件未提交


5. git diff 文件名 //查看修改


6. git log //查看历史




/**恢复操作**/


7. git reset --hard HEAD^ //恢复上一个版本
   git reset --hard HEAD^^ //恢复上上一个版本
   git reset --hard HEAD~100 //恢复前100个版本


8. git reflog //查看所有日志版本号


9. git reset --hard 版本号 //恢复到指定版本


10. git checkout -- 文件名 //恢复文件,包括修改、删除等




/**远程操作**/


11. git remote add origin 网址 //本地与远程连接起来


    git push -u origin master //推送到远程 


12. git clone 网址 //克隆远程库到本地


/**分支**/


13. git checkout -b 分支名 //创建并切换分支


    git branch 分支名 //创建分支
    git checkout 分支名 //切换分支


14. git branch //查看所有分支


15. git merge 分支名B //在A分支操作,将B分支合并分支A分支


16. git branch -d 分支名 //删除分支


17. git merge --no-ff -m "注释" 分支名 //合并分支,禁用fast forward,能找回分支信息


18. git log --graph --pretty=oneline --abbrev-commit //查看所有日志




/**暂存**/


19. git stash //把工作暂存


20. git stash list //查看暂存的工作


21. git stash apply //恢复暂存


22. git stash drop //删除暂存


22. git stash pop //删除暂存并恢复




/**多人协作**/


23. git remote //查看远程库信息


24. git remote -v //查看远程库详细信息


25. git push origin 分支名 //推送到远程指定分支


26. git checkout -b 分支名 origin/分支名 //把远程的分支更新到本地


27. git branch --set-upstream-to=origin/分支名 //设置本地分支与远程分支的连接


28. git pull //获取远程代码


29. git push origin master




/**tag**/
git tag //查看所有标签
git tag -l 1.*.* //打印符合检索条件的tag
git checkout 1.0.0 //查看对应标签状态


git tag 1.0.0-light //创建轻量标签
git tag -a 1.0.0 -m "" //创建带备注标签
git tag -a 1.0.0 f209390 -m "" //针对特定commit版本SHA创建标签


git tag -d 1.0.0 //删除标签(本地)


git push origin --tags //发送本地tag到远程
git push origin 1.0.0 //发送指定tag到远程


git push origin --delete 1.0.0 //git 删除远程分支git版本>1.7
git push otigin :refs/tags/1.0.0 //git 删除远程分支旧版本

猜你喜欢

转载自blog.csdn.net/smile12393/article/details/80763786