Article Directory
In Git, initializing a workspace and using the add and commit commands are basic operations for version control.
Here is a brief explanation of these operations:
Initialize the workspace: Before using Git, you need to initialize the project directory as a Git repository. Open a terminal or command line window in the directory where the project is located, and execute the following command:
git init
This will create a hidden .git folder in the current directory for storing Git related information and version history.
Add files to the staging area (Staging Area): Before version control, you need to add files to Git's staging area. Select the file to commit, and execute the following command:
git add <文件名>
Alternatively, if you want to add all changed files, you can use the following command:
git add .
This will add the current state of the file to the staging area, ready for the next commit.
Submit to the repository: After you have completed a series of file changes and added the corresponding files to the staging area, you can submit. Execute the following command:
git commit -m "提交备注"
This will commit the contents of the staging area to the Git repository and create a new commit record. Be sure to provide a meaningful commit comment within quotes that describes the purpose of this commit or the changes made.
Commits allow you to create uniquely identified versions so that you can roll back or compare differences between versions if needed.
Supplementary Note: Before using the add and commit commands, you may also need to configure Git global user information (username and email). It can be configured with the following command:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
This way, every time you commit, Git will store your identity information with the commit record.
04. GIT local operation - initialize the workspace
Target
说出 git init、git status作用
content
- Initialize workspace
-
The workspace is the directory you can see on your computer. For example, the learn-Git directory we just created, when we first use it, we need to initialize the current folder as the workspace
-
How to initialize the workspace
命令:git init 初始化
Right click on the directory to be initialized workspace, select Git Bash Here
在文件夹中机会出现一个隐藏文件.git如图
当我们在learn-Git文件夹中添加文件的时候,那么这个文件就会被Git所管理
-
check status
We create a readme.txt file in the learn-git directory, and use the vim command to enter the edit mode to add content: the first line of code . You can check its status with the command
命令:git status 查看状态
Red means that it is not currently submitted to the cache
summary
-
How to initialize the workspace
The sign of successful initialization of git init is that there is a hidden directory of .git
-
How to check file status
git status
-
Enter file editing mode linux system
vim filenameThen press the letter i (before) a (after) o (next row) to insert dataThen press esc to exit ==== Finally press: wq to save and exit.
-
View file content: cat file name linux system
05. GIT local operation - add and commit
Target
可以使用 git add将文件添加到暂存区,使用git commit 提交到本地仓库
content
-
Workspace Commit Cache
Use the command in the git console
命令:git add readme.txt
This is done submitting the file from the workspace to the staging area
We check the status through git status
It is found that the file turns green at this time and can be submitted to the local warehouse
-
The cache area is submitted to the local warehouse
命令:git commit -m '第一次提交' 说明:-m 后面跟随的是为你提交的备注,m是单词message信息的首字母 提交信息格式:增删改查第几次提交
Note: If you submit for the first time, you need to fill in the following content:
命令:git config --global user.email '[email protected]'
说明:指定邮箱
命令:git config --global user.name 'suoge'
说明:指定操作者
summary
-
Talk about the role of git add
Add files from workspace to staging area
-
Talk about the role of git commit
Submit the file from the temporary storage area to the local warehouse git commit -m 'information'
-
extension:
添加多个文件 git add [file1] [file2] ... 添加指定目录到暂存区,包括子目录 git add [dir] 添加当前目录下的所有文件到暂存区,不包括被删除的文件 git add . ****** add 时,一个个文件加比较麻烦,可以用下面的命令将所有变动的文件同步至暂存区(新增、修改、删除) git add -A 下面的命令是将所有修改和删除的文件同步至暂存区,不包括新增文件 git add -u