分布式版本控制系统Git经常使用操做

整理git经常使用操做git

1、安装以后设置名字跟email

git config --global user.name "chengguangliang"
git config --global user.email "chengguangliang@oppo.com"github

2、经常使用操做命令

git config --list #检查已有配置信息
git init [file] #把所在目录变成git仓库
git add [file] #把文件提交到暂存区
git commit -m "txt" #把暂存区内容提交到仓库
git diff [file] #查看上次修改内容
git log #查看历史版本历史记录;加上参数--pretty=oneline精简显示
git reflog #查看每次命令记录
git reset --hard HEAD^ [版本号] #回退到上一个版本
git checkout -- file #丢弃工做区修改
本地删除>git rm file> git commit -m "rm file" #删除文件ide

3、远程仓库

(1)添加远程仓库
git remote -v #查看远程仓库信息
git remote add origin git@github.com:leocgl/test.git #关联github远程仓库
git push -u origin master #将本地库当前分支master的内容推送到远程;[-u参数:把本地的master分支与远程的master分支相关联]
(2)克隆远程仓库
git clone git@github.com:leocgl/test.gitrem

4、分支管理

git branch #列出全部分支,当前分支前会标注一个*号
git checkout -b test #建立test分支并切换到test分支上;加上-b选项至关于如下两条命令;等同于git switch -c test
git branch test #建立test分支
git checkout test #切换到test分支;等同于git switch master
git merge test #将test分支合并到当前分支
git branch -d test #删除test分支
git log --graph --pretty=oneline --abbrev-commit #查看分支的合并状况it

相关文章
相关标签/搜索