一小时Git教程(上)

文章

1 课程简介

集中式 SVN

分布式 git

2 安装和初始化

https://git-scm.com/downloads

Git Bash Here

(1)命令行

(2)图形化

(3)IDE插件扩展

windows:posh-Git

git config --global user.name "pony"
git config --global user.email "pony@orcycloud.com"

省略(Local):本地配置,只对本地仓库有效

–global:全局配置,所有仓库有效

–system:系统配置,对所有用户有效

git config --global credential.helper store

保存用户名和密码不用每次都输入

git config --global --list

查看Git的配置信息

3 新建仓库

方式一:

git init

方式二:

git clone
mkdir learn-git
cd learn-git
git init
git inint my-repo
git clone https://gitlab.orcy.net.cn/pony/anti-ad.git

4 Git的工作区域和文件状态

20230911202557

20230911203332

image-20230911203624296

5 添加和提交文件

  • 创建仓库
git init
  • 查看仓库状态
git status

main分支或master分支

  • 添加到暂存区
git add
  • 提交
git commit   # 支持通配符
  • 配置示例
echo "这是第一个文件!" > file1.txt
git add file1.txt
git rm --cached <file>   # 删除暂存区文件
git commit   # 只提交暂存区的文件
git commit -m "第一次提交"   # -m 指定提交信息
git add *.txt  # 支持通配符
git add .  # 添加当前文件夹里所有文件到暂存区
git log # 查看提交记录
git log --oneline   # 查看简洁提交记录

6 回退版本

git reset 工作区 暂存区
git reset –soft
git reset –hard × ×
git reset –mixed ×

查看暂存区内容

git ls-files
git status

回退到上一个版本

git reset --hard HEAD^

查看操作历史记录

git reflog

回退到指定版本

git reset --hard b270efn

误删除也可以找回