The installation of git under windows system and the use of basic commands

1. Git installation

The installation process of git under windows system

2. Git configuration

2.1 Configuration commands

Use Git Bash, that is, LInux operation mode to use git

配置所有用户:git config --system[选项]
配置当前用户:git config --global[选项]
配置当前项目:git config[选项]

Set the user name: take the current user as an example
insert image description here
to set the mailbox insert image description here
User name and mailbox are the basic configuration

The configuration file can be viewed in the following path
insert image description here
insert image description here

View the configuration file: git config --list
At this point, you can see the username and email address we configured
insert image description here

2.2 Basic commands of git

Case: create a git project

Step 1 : Create a project folder (command form operation)
(1) cd switch to the target folder (2) mkdir create a project folder

insert image description here

Step 2 : Initialize the warehouse: git init
meaning: change the entire project directory into a git operation directory, and generate a git local warehouse. That is, the project can be viewed using git management. At this time, the project folder is equivalent to the root directory of the git management project; the workspace, temporary storage area and warehouse are ready
(1) enter the project directory (2) initialize the warehouse Result: a hidden file .git
is generated under the git project file

insert image description here
insert image description here

Step 3 : View the status of the local warehouse: After git status
is initialized, the warehouse works on the master branch by default. When the work area is inconsistent with the warehouse area, it will remind you.
Explanation of the query results:
(1) on branch master: located in the branch master
(2) No commits yet: namely Files not recorded in the temporary storage area
(3) nothing to commit (create/copy files and use “git add” to track): There are no files in the operation area that need to be submitted to the temporary storage area for record

insert image description here

Step 4 : You can write the project under the Project folder. Here, for the sake of intuition, some files
can be manually copied and created using commands (purpose: to consolidate the use of linux commands)

insert image description here

Step 5 : Submit the workspace files to the temporary storage area
(1) Step 4 stores the files under the project folder, first check the warehouse status at this time
(2) Submit to the temporary storage area for records [Note: Tracking folders are not supported ]
git add [file name] can be multiple
git add * represents all files, but does not include hidden files
Untracked files: Untracked files
Changes to be committed
(3) Unstaged (tracked) files: git rm -cached file name
insert image description here
Tracking a file is recorded in the temporary storage area

insert image description here
insert image description here
unstaged file
insert image description here

Step 6 : Submit the records in the temporary storage area to the warehouse
git commit [file name] -m[message] Description: -m means add some synchronization information to express the synchronization content
Example: Submit all the files in the temporary storage area to the warehouse
file submission After arriving at the warehouse, it shows no file submission, clean workspace

insert image description here

Step 7 :
(1) If a file submitted to the warehouse is modified in the operation area, the file needs to be resubmitted
(2) The content of the modified file can be compared with the last submission of the file submitted to the warehouse

(3) Check the submission log (several submissions, submission content)
case: modify the 1.txt file

insert image description here
insert image description here

Display content analysis: a represents the 1.txt uploaded to the warehouse; b represents the modified workspace. The +sdsa... below represents the modified content.
insert image description here
The above figure shows the synchronization information after -m when submitting

Step 8 : The operation area wants to restore the content of the file uploaded to the warehouse (the deleted file can also be restored, provided that the warehouse is uploaded)
git checkout – file name

insert image description here

Step 9 : Move or delete the file
git rm [file name] This operation also deletes the workspace file
git mv [to move the file] [target folder]
The above two operations are at the same level as add, just commit to the warehouse directly. As shown below

insert image description here

2.3 Recovery after file deletion

git rm [文件名]
使用 git rm[文件名] 操作,同时会删除工作区的文件,如果要恢复,采用以下方法

2.3.1 Scenario 1 – Not submitted to the warehouse

git checkout HEAD -- [文件名]

insert image description here

2.3.2 Scenario 2 - Submitting to the warehouse

Added after solving...

2.3.4 Delete but keep workspace files

git rm -r --cached [文件名]
此时删除操作需提交至仓库,同时1.txt文件需要重新在暂存区记录。如果不提交删除操作,直接将1.txt直接追踪,则二者抵消

insert image description here
insert image description here

Summarize

  1. Empty folder upload warehouse is not supported, it can be a compressed package
  2. git add\mv\rm belongs to the same level of operations, and both need to be committed to the warehouse. Mv\rm causes files in the workspace to be deleted or moved as well.
  3. Keep the workspace consistent with the file content of the warehouse , that is, the last display:

insert image description here

Guess you like

Origin blog.csdn.net/m0_51489557/article/details/130317360
Recommended