Master the Git workflow (1)-basic git operations

Basic operation outline:

 

Master the Git workflow (1)-basic git operations

Master the Git workflow (2) - git branch management

Master the Git workflow (3)--git workflow

1. Introduction to git

Git adopts distributed system management, which can easily manage the code in a certain directory

2. Installation and Configuration

3. Create a repository

 Create a new directory git test, create a version library in the git test directory, the command is as follows:

mkdir git_test

cd git_test

git init

Create a repository through git init, so that git can manage the code in the directory. You can see that a hidden .git directory is created under the git_test directory, which is the repository directory;

4. Version creation and rollback

1) use

The creation of a file version is divided into two steps: add and commit submission. The -m submitted through commit is just a description information. The description information of different versions can be the same, but the serial number of the submitted version must be different.

git log

 

If you feel that version 2 is not as good as version 1, you can also perform a rollback operation:

After returning to version 1, git did not delete version 2, but just pointed the Head to version 1. Then you can revert to the specified version according to git reset.

If you cannot find the serial number of the version, you can use the git reflog command to view the record of the operation, so as to roll back:

go reflog

2) Work area and temporary storage area

The directory that helps you manage on your computer, git_test is a workspace.

There is a hidden directory .git in the workspace. This is not a workspace, but a git repository;

There are many things stored in the git repository, the most important of which is the staging area called stage (or indx) , the first branch master automatically created by git for us, and a pointer HEAD to master.

And add can also follow multiple files or directories;

summary:

1. Edit files are all edited in the work area;

2. Git add is to add the modification of the file to the temporary storage area, and git commit is to create a version record of the things added by git add at a time;

3) Management modification

summary:

git commit will only submit the version in the staging area.

4) Undo the modification

Not added to the temporary storage area:

Added to the temporary storage area:

Note: After passing git checkout - file, the file will be restored to the unmodified version, so be careful!

5) Differences in comparison files

Summary: Compare the file differences between the two versions

HEAD^ means the previous version of HEAD

6) Delete files

After deleting by rm operation,

You can use git add or git rm to put the file into the temporary storage area;

Then upload the temporary storage area through git commit;

Note: If you want to return the file after putting the file into the temporary storage area through git rm, you can do the same as before: first cancel the operation through git reset, and then discard the modification of the temporary area through git checkout.

The other is to use the checkout method to restore data:

Note:

1. View the submitted version records through git log or git log --pretty=oneline;

2. Deleting a file is also a change to the workspace. You can change the change to the workspace through git checkout.

Guess you like

Origin blog.csdn.net/qq_29027865/article/details/94741429