[Git\GitHub\GitLab study notes] Version Control Git Video Tutorial Complete Works (62P) | 6 hours from entry to master (P20-P26)

table of Contents

  1. P20-Retrieve files after permanent deletion
  2. P21-Retrieve deleted files added to the temporary storage area
  3. P22-Summary of the way to retrieve deleted files
  4. P23-Compare files (compare file differences)
  5. P24-Branch Overview
  6. P25-branch operation
  7. P26-Resolve conflicts after merging branches

P20-Retrieve files after permanent deletion

Description: How to restore the files that have been submitted to the local library after deletion

vi aaa.txt
git add aaa.txt
git commit -m "new aaa.txt" aaa.txt
git status #查看状态
rm aaa.txt #删除文件
ll #查看当前文件夹下面的文件,发现aaa.txt已经不见了被删除
git commit -m "del aaa.txt" aaa.txt 
git reflog #查看日志 将指针移动到aaa.txt文件commit的那个版本
git reset --hard [哈希值]
ll	#查看,发现之前被删除的文件被恢复了

P21-Retrieve deleted files added to the temporary storage area

vi apple.txt
git add apple.txt
git commit -m "add apple" apple.txt
ll #查看当前目录下的文件
rm apple.txt #删除apple.txt文件
git add apple.txt # 将删除文件操作提交至缓存区
git reset --hard HEAD #恢复到上一次提交到本地库操作的状态 即可恢复文件

Insert picture description here

P22-Summary of the way to retrieve deleted files

Retrieving deleted files.
Prerequisite: Before deleting, the existing state of the file is submitted to the local library, otherwise it cannot be retrieved through git
Operation: git reset --hard [pointer position]
1. When the delete operation is submitted to the local library: point the pointer position to delete The previous position
2. When the delete operation has not been submitted to the local library: the pointer position uses HEAD

P23-Compare files (compare file differences)

git diff filename #与暂存区进行比较

git diff [file name]: Compare the files in the work area with the temporary storage area
git diff [historical version in the local library] [file name]:

  • Compare the files in the workspace with the local library history
  • Without file name, compare the differences between multiple files
    Insert picture description here

P24-Branch Overview

What is a branch

In the version control process, use multiple items to advance multiple tasks at the same time. (When the branch was just created, the main branch and the newly created branch have the same content)
Insert picture description here

benefit

1. When developing new functions, each branch is in the development process. If a branch fails to develop, it will not have any impact on other branches. The failed branch can be deleted and restarted, which is convenient for trial and error. Novice developers generally develop in branches.
After the branch is developed and tested, it can be merged with the Master.
2. Simultaneously promote the development of multiple functions in parallel to improve development efficiency, independent of each other, and faster product iteration.

P25-branch operation

View the current branch

git status

Insert picture description here

Create new branch

git branch hot_fix(新分支的名字)

Insert picture description here

View all branch information and version numbers (-v)

git branch -v

Insert picture description here

Switch branch

git checkout [分支名]

Insert picture description here

Merge branch

  • The first step: switch to the branch that accepts the modification (new content is merged)
git checkout [被合并的分支名]
  • The second part: execute the merge command
git merge [有新内容的分支名]

Insert picture description here

Insert picture description here

P26-Resolve conflicts after merging branches

Why is there a conflict?
When two branches modify the same file at the same location, conflicts will occur during merging. Open the conflicting file as shown in the figure below:
Insert picture description here
Conflict mark:
<<<<<< HEAD
xxxxxx

xxxxxx
<<<<<< [branch_name]
Insert picture description here

Conflict resolution

  • Step 1: Edit the file and delete special symbols
  • Step 2: Modify the file until you are satisfied
  • The third step: git add
  • The fourth step: git commit -m "log information"
    • Note: At this time, commit cannot carry a specific file name
      Insert picture description here

Guess you like

Origin blog.csdn.net/kz_java/article/details/114592383