doc/笔记/Git基本使用.md

105 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# git基本使用
## Git的安装
官网https://git-scm.com/downloads
## Git基本概念
工作区 -> 暂存区 -> 版本库
## Git常用操作
### 仓库初始化
```sh
git init
```
### 提交到暂存区
```sh
# 提交当前全部
git add .
# 提交指定文件
git add fileName
```
### 从暂存区checkout文件相当于恢复到修改前的状态
```sh
git checkout -- fileName
```
### 提交版本库
```sh
git commit -m '备注'
```
### git push
命令格式
```
git push <远程主机名> <本地分支名>:<远程分支名>
```
将本地的 master 分支推送到 origin 主机的 master 分支
```
git push origin master
```
等价于
```
git push origin master:master
```
从版本库恢复最近一次版本(覆盖暂存区、工作区)
```sh
# --hard 强制覆盖,会把暂存区和工作区内的文件一起覆盖
git reset --hard head
```
从版本库恢复最近一次版本(不会覆盖暂存区)
```sh
git reset head
```
回退指定版本
```
git reset --hard 版本号
```
查看日志
```
git log
```
```
git log --graph
```
```
git log --online
```
```
git log --graph --online
```