Home > Development Tools > git > body text

An article summarizing the basic usage of Git

PHPz
Release: 2023-04-03 09:25:17
Original
693 people have browsed it

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.

Git installation

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
Copy after login

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.

Get started with Git

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
Copy after login

This command will initialize the status of the Git warehouse and create a .git directory in the current directory, containing Git All management information.

Basic Git operations

  1. Check the status of the warehouse

Use the following command to check the status of the Git warehouse:

git status
Copy after login

Output The result tells you the current branch and warehouse status, including:

On branch master
nothing to commit, working directory clean
Copy after login

means that the current branch is the main branch, there are no new changes, and the working directory is clean.

  1. Add files

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
Copy after login

If you want to add the entire directory, please use the following command:

git add .
Copy after login
  1. Commit changes

After adding or modifying files, you should use the command to commit the changes:

git commit -m "commit message"
Copy after login

Among them, the commit message is a brief introduction to the modifications you have made.

  1. View submission history

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
Copy after login

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
Copy after login

This history information can help you understand the environment status between submissions and their corresponding submissions.

  1. Branching and merging

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
Copy after login

Summary

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template