Home > Article > Development Tools > An article summarizing the basic usage of Git
Git is one of the most popular version control systems today, which helps developers manage and coordinate versions of code. As team projects increase, the use of Git becomes more and more popular. This article will introduce the basic use of Git.
Installing Git is a prerequisite for using Git. The installation method varies depending on the operating system you are using. If you are using a Linux distribution, you can install Git using the system's own package manager.
Take Debian as an example, use this command to install Git:
sudo apt-get update sudo apt-get install git
If you are using Windows or MacOS, it is recommended to download the latest version of the git.exe installation package from the Git official website, follow Instructions for installation.
Git can be used in any folder. If you want to use Git to manage a warehouse, you can enter the warehouse root directory and initialize the Git warehouse:
git init
This command will initialize the status of the Git warehouse and create a .git directory in the current directory, containing Git All management information.
Use the following command to check the status of the Git warehouse:
git status
Output The result tells you the current branch and warehouse status, including:
On branch master nothing to commit, working directory clean
means that the current branch is the main branch, there are no new changes, and the working directory is clean.
In the directory managed by the Git repository, whenever you edit a file, you need to tell Git to add the file to the repository. This command converts your working directory into a file that the Git repository can track:
git add filename
If you want to add the entire directory, please use the following command:
git add .
After adding or modifying files, you should use the command to commit the changes:
git commit -m "commit message"
Among them, the commit message is a brief introduction to the modifications you have made.
By viewing submission history, you can learn about all submissions and changes in the warehouse. Use the following command to view the commit history:
git log
This will output all commit cancellations since entering the commit history, including commit time, author, title, commit description, and SHA-1 hash:
commit 6983f89439dbf09dc1a66207ed830f1a54630f7f (HEAD -> master) Author: Tom <tom@acme.com> Date: Thu Nov 22 01:51:13 2018 -0500 Add new feature commit e028ac9be18c313bdb96bfc3c3cd0d8fbf7c6c1b Author: Tom <tom@acme.com> Date: Wed Nov 21 11:51:13 2018 -0500 Initial commit
This history information can help you understand the environment status between submissions and their corresponding submissions.
Git allows you to merge different branches together using the convenient git merge command. For example, to merge the master branch and the dev branch, run on master:
git merge dev
In this article, we learned about the basic usage of Git, such as installing Git, initializing Git repository, Add files, commit changes, view commit history, branch and merge, and more. Once you learn to use these basic features, you can more easily manage and coordinate versions of your code with Git.
The above is the detailed content of An article summarizing the basic usage of Git. For more information, please follow other related articles on the PHP Chinese website!