-
Notifications
You must be signed in to change notification settings - Fork 0
Home
maxminute edited this page Apr 4, 2020
·
2 revisions
[toc]
Git版本查看
$ git --version
配置 user.name
$ git config --global user.name 'your_name'
配置 user.email
$ git config --global user.email 'your_email@domain.com'
缺省等同于local
# local只对某个仓库有效
$ git config --local
# global对当前用户所有仓库有效
$ git config --global
# system对系统所有登录的用户有效
$ git config --system
显示config的配置信息,加--list
$ git config --list --local
$ git config --list --global
$ git config --list --system
- 把已有的项目代码纳入Git管理
$ cd 项目代码所在的文件夹
$ git init
- 新建的项目直接用Git管理
$ cd 某个文件夹
$ git init your_project #会在当前路径下创建和项目名称同名的文件夹
$ cd your_project
查看版本历史
$ git log
显示git状态
$ git status
添加文件到暂存区
$ git add files
提交文件到版本库
$ git commit -m 'somethings'
Git提交的步骤
# 将文件添加到暂存区
$ git add files
# 将文件提交到版本库
$ git commit -m 'somethings'
一次性将所有修改的文件添加到暂存区
$ git add -u
- 普通方式
# 将文件重命名
$ mv name new_name
# 将新文件添加到暂存区
$ git add new_name
# 将旧文件删除
$ git rm name
撤销上一次修改
$ git reset --hard
- Git命令方式
$ git mv name new_name
查看简洁列表
$ git log --oneline
查看最近的几个commit
$ git log -n3
查看当前版本的历史
$ git log
查看所有分支的历史
$ git log --all
图形化查看所有分支的历史
$ git log --all --graph
查看git帮助文档(log指令)
# 查看git log命令的帮助文档
$ git help log
# web方式查看git log命令的帮助文档
$ git help --web log
查看分支
# 查看所有分支
$ git branch -a
# 查看各分支详细信息
$ git branch -v
# 查看所有分支详细信息
$ git branch -av
创建分支(并直接切换到这个分支)
$ git checkout -b temp d5dee8d638526c219b8ab
直接将文件提交到版本库(省去了git add步骤)
$ git commit -am 'somethings'
切换分支
$ git checkout master
查看git存放的对象(object)的类型
$ git cat-file -t 6e8f2ab60c60b40760821ccd8c7e2bee1c0f8266
查看git存放的对象(object)的内容
$ git cat-file -p 6e8f2ab60c60b40760821ccd8c7e2bee1c0f8266
- HEAD文件:ref: refs/heads/master 当前工作分支信息
- config文件:存放了配置信息(本地仓库相关)
- refs文件夹:
- heads文件夹:所有分支信息
- tags文件夹:所有的标签(里程碑)照片
- objects文件夹:
byebye