Configuration management Git usage tutorial

Git initialization configuration

git config --global user.name "xxx" # 配置Git的用户名
git config --global user.email "[email protected]" # 配置用户的电子邮箱
git config --global core.quotepath false # 不将路径名编码(防止中文不能正确显示)
git config --global --list # 查看配置信息内容

 The command to initialize the local repository

# 初始化版本库(创建一个新的版本库),在一个指定的文件夹下,将这个文件夹变成版本仓库文件夹
# 默认创建出一个名为master的分支(版本仓库的名字)
git init

basic command

 # View the status of file changes (workspace, staging area, warehouse)

git status

# Add untracked files, or "changes" (modification, deletion) of tracked files to the temporary storage area

git add 文件名
git add 文件夹名 # 将文件夹中及后代文件夹中的所有文件的变更通通加入暂存
git add . # 将当前目录下(整个仓库文件夹)的所有文件及文件夹的后代文件的变更,通通加入暂存
git add *.txt # 将所有的后缀名为.txt的文件加入暂存

# Submit the changes (new files, modification, deletion) of the files in the temporary storage area to the version warehouse, forming a submission version, and you must specify the "commit description" # Each submission will form a version,
each The version has a unique version number (HASH code), the user name and email address of the submitter, date, and submission instructions

git commit -m "提交说明" # 提交暂存区中所有文件或文件夹的变更
git commit -m "提交说明" 文件名 # 提交暂存区中指定文件或文件夹的变更
git commit -am "提交说明" # 将已跟踪的文件但未暂存的变动加入暂存区,紧接着再提交。

# If it is a new file that has not been tracked, you still need to add it independently, and then commit
# Delete the file from both the workspace and the temporary storage area. After deletion, there is no need to add the "deleted change", and it can be submitted directly

git rm 文件

# View all submitted version information

git log # 多行版本提交信息
git log --pretty=oneline # 单行版本提交信息
git log --oneline # 单行版本信息(7位的提交HASH码)
git log --oneline --graph # 含有分支合并时各自提交的“分支”的图形效果

# Version backtracking: overwrite the workspace and staging area with the version specified in the repository

git reset --hard HEAD^^ # 回溯到当前版本的前2个版本
git reset --hard HEAD~8 # 回溯到当前版本的前8个版本
git reset --hard 版本的HASH码 # 回溯到指定HASH码的版本(HASH码最少写出4位)

# View commits, backtracking, branches, and checkout records of all version changes

git reflog

# Undo modification: overwrite the content in the workspace with the one in the temporary storage area

git checkout -- 文件名 # 记得加--,它的前有空格

Guess you like

Origin blog.csdn.net/qq_46366184/article/details/130387291