Home  >  Article  >  Development Tools  >  This article will help you understand what Git version management is

This article will help you understand what Git version management is

WBOY
WBOYforward
2022-02-21 17:53:292824browse

This article brings you relevant knowledge about Git version management. The version management tool can record each modification. As long as it is submitted to the version repository, you can find the status at any previous time. ,I hope everyone has to help.

This article will help you understand what Git version management is

Git is a "distributed version management tool".
The version management tool can record every modification. As long as it is submitted to the version warehouse, the status at any previous time can be found.
We have all used the undo function when writing, but undo can only go back a limited number of steps. Usually, the editing software is closed and then reopened. At this time, the undo record has been cleared. The "version management tool" is different. It can record every modification. As long as it is submitted to the version warehouse, you can find the status at any previous time.

Create warehouse

After installing the git software, create a new folder in any directory, open it, and then execute git init to create a new git warehouse (this command A hidden subdirectory named .git will be created).

Check out the warehouse

Execute the command git clone remote project address to clone the warehouse on the remote server.

Git status

Git has three states, namely committed, modified, and staged.

  • Modified: Modified means that the file has been modified but has not been saved to the database.
  • Staged (staged): Indicates that the current version of a modified file has been marked so that it will be included in the next submitted snapshot.
  • Committed: The data has been safely saved in the local database.

The three states of Git correspond to the three workflows of the local warehouse. This low warehouse is composed of three trees maintained by git.

  • The first one is the working directory, which holds the actual files, additions and deletions of files and content;
  • The second one is the temporary storage area (Index), which is like a cache area and is temporarily saved. change. Enter git add filename, and the changes will be placed in the temporary storage area.
  • The third one is HEAD, pointing to the last submitted result. Enter the git commit command, and the changes will be placed in the local warehouse. What comes after the commit can be called a version.
    This article will help you understand what Git version management is

Basic git workflow:

  • Propose changes (add to staging area)
    Use the command git add (for a specific file) or git add * (for all files) can propose changes (add them to the staging area).
  • Submit changes
    Use the command git commit -m "code submission information" to actually submit the changes. After execution, the changes are submitted to HEAD, but have not yet reached the remote warehouse.
  • Push changes
    Use the command git push origin master to submit the changes to the remote warehouse master branch (usually not submitted directly to the master branch, but pushed to your own branch, and then merge after verification ).

Branch

The master branch was mentioned earlier, so how to understand the branch intuitively?

Branches are used to insulate feature development. When creating a repository, master is the "default" branch. Develop on other branches and merge them into the master branch when finished.
This article will help you understand what Git version management is

git branch test1 Create a branch named test1.
git checkout test1 Switch the current branch to test1
git checkout -b test1 Create a branch called "test1" and switch to it.
git checkout master Switch back to the master branch.
git branch -d test1 Delete the newly created branch.
git push origin Push the branch to the remote warehouse.
git merge test Merge branches.

Update and merge

Use the command git pull "remote branch name" to get the code from the remote and merge it into this lower version (get (fetch) in the working directory and merge ( merge) Remote changes)
Use the command git merge "branch name" to merge other branches into the current branch.

In the first two cases, git will try to automatically merge the changes. However, conflicts may occur during merging, and you need to manually modify the files to merge these conflicts. After making changes, execute git add to mark them as merged successfully. Before merging changes, you can use git diff to observe whether there are differences.

Replace local changes

If you make a mistake, you can use the command git checkout - to replace the local changes. This command will replace the files in the working directory with the latest content in HEAD (changes and new files that have been added to the staging area will not be affected)

Removal and reinstallation of remote warehouses Naming

Rename test to test1: git remote rename test test1
Remove remote warehouse test1: git remote rm test1

Undo operation

Cancel the temporary file: git reset filename
Undo the modification to the file: git checkout –filename

History record

Use git log You can get the history of the local warehouse.
Use the command git log --author=bob to view only the commit records of a certain person. Add some parameters to modify the output to get the results you want.
Check which files have changed: git log --name-status

Recommended study: "Git Tutorial"

The above is the detailed content of This article will help you understand what Git version management is. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete