Git 分布式版本控制常用命令(1)

  • 安装完成后,标定自己身份,配置自己的姓名与邮箱
git config --global user.name "Name"
git config --global user.email "example@mail.com"
  • 初始化Git仓库
git init
  • 添加文件到Git仓库
git add <file>
git commit -m "Add some comment"
  • 查看日志
git log		#提交历史
git reflog	#命令历史
git status  #各个区的状态变化
  • 回退到某个版本
git reset --hard HEAD^   #上个版本
git reset --hard commit_id # 跳转到commit_id的版本,id只需要前几位

工作区、暂存区、版本控制区
工作区: 当前工作目录
暂存区: git add < file > 增加的文件进入暂存区
版本控制区: git commit 将文件加入master管理版本


  • 丢弃工作区的修改
git checkout --file   #  丢弃工作区对file的修改, 回到最近一次add或commit的状态
  • 撤销暂存区的修改到工作区
git reset HEAD file
  • 删除文件
git rm file # 相当于rm后commit
  • 链接本地仓库与远程仓库
git remote add origin "github上新建仓库时给的链接.git"
  • 本地仓库内容提交到远程仓库
git push -u origin master # 第一次
git push origin master # 以后
  • 远程仓库下载
git clone "要下载github的url"

分支管理

  • 创建分支
git branch <name>
  • 切换分支
git checkout <name>
  • 创建新的分支并切换分支:
git checkout -b <name>
  • 查看分支
git branch
  • 合并分支到当前分支
git merge <name>
  • 删除分支
git branch -d <name>
原文地址:https://www.cnblogs.com/Alruddy/p/8040279.html