git常用命令
git 常用命令总结
1、git初始化
git init
2、初始化配置
本地配置:
git config user.name AlexMa
git config user.email 1611224578@qq.com
系统配置:
git config --global user.name AlexMa
git config --global user.email 1611224578@qq.com
3、git 从本地文件提交暂存区
git add <filename>
git add .
4、git 撤销提交到本地暂存区的文件
git rm --cached <file>
5、git 从暂存区提交到本地仓库
git commit <file>
git commit .
git commit -m "ane filename" <file>
6、状态查看操作
git status
7、查看版本的历史命名
git log (最完整的形式)
git log --pretty=oneline ()
git log --oneline (hash缩短显示)
git reflog (移动到当前版本需要多少步)
8、前进后退命令
git reset --hard <hash值> 指定到指定的版本。
9、删除文件并找回
前提:删除前,文件存在时的状态已经提交到本地库
10、找出文件之前的差异
git diff .
分支管理:
查看分支的状态
git status
查看分支:
git branch
git branch -v
创建分支
git branch hot_fix
切换分支
git checkout hot_fix
合并分支
git checkout master
git merge hot_fix
11、github远程仓库
给远程仓库起别名:
git remote add origin https://github.com/mgb1611224578/huashan.git
查看远程仓库
git remote -v
提交本地仓库代码到远程仓库
git push origin master
克隆远程仓库(有三个效果 完整把远程库下载到本地、已经初始化、创建origin别名)
git clone https://github.com/mgb1611224578/huashan.git
指定远程分支拉取代码
git clone -b master https://github.com/mgb1611224578/huashan.git
抓取远程库中的代码
git fetch origin master
切换到origin的master
git checkout origin/master
git merge origin/master
拉取远程代码
git pull origin mater
pull=fetch + merge
查看git提交的所有历史记录
git reflog
查看当前的文件管理状态(已提交|未提交)
git status
图解:

浙公网安备 33010602011771号