Basic introduction to the working principle of git's workspace and staging area

After registering an account , create a repository to manage your code files. First, create an empty directory, I just create an empty folder as git, and then enter git init in the git directory, so that the git repository is built. There will be a .git hidden directory under the folder git (available to view with ls -a). There are many things stored in the Git version repository, the most important of which is the temporary storage area called stage (or index), the first branch master that Git automatically created for us, and a pointer to master called HEAD .

Workspace (Working Directory)It is the directory you can see on your computer, for example, my git folder is a workspace.


When adding files to the Git repository, it is performed in two steps:

The first step is to use ** git add <file> ** to add the file, which is actually to add the file modification to the temporary storage area ( note: it is the change of the file in the workspace, if there is no change, then add no );

The second step is to use ** git commit ** to commit the changes, which is actually to commit all the contents of the staging area to the current branch.It can be simply understood that the file modifications to be submitted are all placed in the temporary storage area, and then all modifications in the temporary storage area are submitted at one time.

Example test:

1. Use git status to view the status of the current directory as follows,


2. Create a doc1.txt file, and then check that the status is untracked. This is because it has not been added to the temporary storage area, so the Git manager cannot track it


3. After adding the file to the file, check the status


The status of the current temporary storage area Stage is like this


4. Next, add the contents of the staging area to the current branch through git commit


The current state of the repository is like this. There is no content in the staging area.


5. Your workspace is clean if you haven't made any changes to it


Well, that's about it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325570592&siteId=291194637