How to use git (terminal input command)

Preface

Today I will walk you through the git process step by step:
install git (see the git document I posted before for details) git document
After that, we first register a gitee account. gitee is a lazy person who creates a remote warehouse and just registers...

1. Create a warehouse

  • First create an empty folder and name it whatever you want

  • In the compiler, enter the folder terminal or cmd to enter a black window.

  • **Enter the command to create a warehouse

 git init

Insert image description here
A git configuration file will appear. If it is not displayed, it means that the hidden folder is closed and we can open it.
Insert image description here

  • After creating the warehouse, we need to configure our own username and email (in multiplayer cooperation mode, we can more clearly know who uploaded and submitted it)
git config user.name "你的姓名"
git config user.email "你的邮箱"

Lose line by line. Any email address is acceptable. After configuring the user information, we can use the command to view the user information.

git config --list

Insert image description here
If you can see the user information, the configuration has been completed.

2. Create files and modify data

Create a file

cd . > 文件名

Insert image description here
If the folder automatically generates files, the command will take effect. You can also create files directly in the folder

state

At the same time, git provides three (or four) different record states.

  • Modified
  • Staged
  • Committed

has a special status

  • Untracked

PartitionPartition

git status   //可以查看你文件的状态

The red status indicates that the file you just created is now in the workspace
Insert image description here

git  add .   //文件夹里面所有文件提交到暂存区(红色状态变绿色)
git add 文件名  //单个文件提交暂存区
# 添加多个文件
git add 2.txt 3.txt
# 添加整个目录
git add ./a
# 添加多个目录
git add ./b ./c

The green status indicates that your file is currently in the staging area.
Insert image description here
Files in the staging area can be submitted to the warehouse (that is, files in the green status can be submitted).
Use git status to check the file status.

git commit  // 把暂存区的文件提交到仓库(只限暂存区)
git commit -m 可以备注的信息   // 加 -m  既可以把暂存区的文件提交到仓库也可以备注信息(建议使用)

Insert image description here
After using git commit -m to note the information, you can use the command to view the information of the note and when the note was made.

git log  //查看你使用 git commit -m 备注的信息 
git log --oneline  //查看你使用 git commit -m 备注的信息 简化版

Insert image description here
Insert image description here
Another situation is
Insert image description here
to deal with garbled codes.

git config --global core.quotepath false
git config --global gui.encoding utf-8
git config --global i18n.commit.encoding utf-8
git config --global i18n.logoutputencoding utf-8
set LESSCHARSET=utf-8

Enter line by line. Enter a line and press Enter. After entering five instructions, use git log to check the time of file submission and the user information of who submitted the file.

3. Delete, Undo Reset, and Compare

When the death method is used, just take it directly

delete

git rm 文件   //  从 git 仓库与工作区中删除指定文件


git rm --cached 文件  // 只删除 git 仓库中的文件

git commit -m 修正  //以后,需要 commit 这次操作,否则 rm 将保留在暂存区

Cancel

Only when the file is in the green state is it recalled that the file is in the temporary storage area. Undo the files in the temporary storage area and turn them into red, which is the work area status.

Undo from staging area to workspace

// 从暂存区中撤销一个指定文件
git reset HEAD 文件名称
// 从暂存区撤销所有文件
git reset HEAD .

This command can be used to roll back the version , so when files are submitted to the warehouse or modified or changed, you must use git commit -m to note the status so that you can operate better.

//回退到指定的 commitID 版本  这个commitID 就是 git log 或者 git log --oneline 的绿色值 你可以通过值 回到你需要的版本



git reset --hard commitID

Compare

# 比较 工作区和暂存区
git diff 文件 
# 比较 暂存区和仓库
git diff --cached [commitId] 文件
# 比较 工作区和仓库
git diff commitId filename
# 比较 仓库不同版本
git diff commitId1 commitId2

Summary
: Due to time constraints, I will only write half of the file and I will fill in the rest. I hope everyone can support it.

Reference link: git documentation

Guess you like

Origin blog.csdn.net/www61621/article/details/129207077