Git Cheatsheet Part 1: Overview

Git Cheatsheet Part 1: Overview

Table of Contents

初始化

初始化设置用户名和邮箱

1
2
3
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global credential.helper store

创建仓库

创建一个新的本地仓库(忽略project-name则在当前目录创建)

1
git init <project-name>
下载一个远程仓库
1
git clone <url>

Git的四个区域

  • 工作区 (working directory): 就是你在电脑里看到的目录
  • 暂存区 (Stage/Index): 一般存放在.git目录下面
  • 本地仓库 (Repository): 工作区有一个隐藏目录的.git,这个不算工作区,而是Git的版本库
  • 远程仓库 (Remote): 托管在远程服务器上的仓库

Git的三种状态

  1. 已修改 (Modified): 修改了文件,但没保存到暂存区
  2. 已暂存 (Staged): 把修改后的文件放到了暂存区
  3. 已提交 (Commited): 把暂存区的文件提交到本地仓库

特殊文件(夹)

  • .git: Git仓库的元数据和对象数据库
  • .gitignore: 配置不需要提交到仓库的文件
  • .gitattribute: 指定文件的属性,比如换行符
  • .gitkeep: 使得空目录也能提交到仓库
  • .gitmodules: 记录子模块的信息
  • .gitconfig: 记录仓库的配置信息

基本分支

  • main: 默认主分支
  • origin: 默认远程仓库
  • HEAD: 指向当前分支的指针
  • HEAD^: 上一个版本
  • HEAD~4: 上四个版本

Git Cheatsheet Part 1: Overview

https://jerry20000730.github.io/wiki/Git/git1/

Author

Tragic Master

Posted on

2023-10-13

Updated on

2023-10-13

Licensed under