Introduction to several commonly used commands in git

A compilation of commands you must know

  • 1, it's hot

Initialize a new Git repository.

This will create a subdirectory called ".git" in the current directory, where Git will store the metadata for all repositories.

  • 2,git clone

Clone an existing repository.

This creates a copy of the local repository, including all of its history and branches.

git clone <repository link>

  • 3,git add

Add the modifications to the next commit.

This will add the specified files to the staging area, which will be included in the next commit.

git add file1.txt file2.txt

  • 4,git commit

Create a new commit.

This will record changes to the staging area and any other changes made since the last commit, along with a commit message describing those changes.

git commit -m "Add new features"

  • 5,git push

Push commits to the remote repository.

This will send the local commits to the specified remote repository, updating the remote branch to include the new commits.

git push origin main

  • 6,git pull

Get and merge changes from remote repository. This fetches the latest commits from the specified remote repository and merges them into the current branch. git pull origin main

  • 8,git branch

List, create or delete branches. This command can be used to list the branches available in the repository, create new branches or delete existing branches. git branch new-branch

  • 9,git checkout

Switch to a different branch. This command allows you to switch to a different branch in the repository and make it the current working branch. git checkout main

  • 10,git merge

Merge one branch into another branch. This command merges changes from one branch into another branch, creating a new commit that reflects the merged changes. git merge new-branch

  • 11, the status quo

Displays the status of the warehouse. This command displays the current branch, any staged or unstaged changes, and any untracked files. git status

  • 12,git fox

Merge changes from one branch to another branch. Suppose you made some changes on the "XYZ" branch, and you want to merge these changes into the "main" branch. You can use the git rebase command to re-apply your changes to the main branch.

  • 13,git stash

Temporarily save changes that are not yet ready for submission. If your changes are not ready to be committed, but you want to switch to another branch to continue working, you can temporarily save your changes for later use and switch branches without losing progress.

  • 14,git revert

Let's say you made a mistake in a previous commit and need to undo it. You can use git revert to create a new commit that undoes the changes introduced by the previous commit. git revert <commit1>..<commit2> Learn these 14 Git commands, which are the commands you use most frequently in daily development.

Explain what each command does

The first is git init, which is used to initialize a new Git repository. After executing this command, Git will create a subdirectory named ".git" in the current directory, which stores all metadata of the warehouse.

Next is git clone, which is used to clone an existing warehouse. After executing this command, you will create a local copy of the repository, including all history and branches.

The git add command is used to add modified files to the staging area of ​​the next commit. You can specify the files to be added. The git add command is used to add modified files to the staging area of ​​the next commit. You can specify the files to add, such as git add file1.txt file2.txt.

The git commit command is used to create a new commit. It records changes to the staging area and other changes since the last commit, along with a commit message describing these changes, such as git commit -m "Add new features". The git push command is used to push commits to the remote repository. It will send local commits to the specified remote repository and update the remote branch to include the new commits, such as git push origin main.

The git pull command is used to get and merge changes from the remote repository. It will get the latest commit from the specified remote repository and merge it into the current branch, such as git pull origin main.

The git branch command is used to list, create or delete branches. You can use this command to list the branches available in the repository, create a new branch, or delete an existing branch, such as git branch new-branch.

The git checkout command is used to switch to a different branch. You can use this command to switch to a different branch in the repository and make it the current working branch, such as git checkout main.

The git merge command is used to merge one branch into another branch. It merges the changes from one branch into another branch, creating a new commit reflecting the merged changes, such as git merge new-branch.

The git status command is used to display the status of the warehouse. It shows the current branch, any staged or unstaged modifications, and any untracked files, such as git status.

The git rebase command is used to merge changes from one branch to another branch. Suppose you made some changes on the "XYZ" branch, you can use the git rebase command to re-apply these changes to the "main" branch.

The git stash command is used to temporarily save changes that are not yet ready for submission. If your changes are not ready to be committed, but you want to switch to another branch to continue working, you can use the git stash command to stage the changes for later use.

The git revert command is used to undo previous commits. If you made a mistake in a previous commit, you can use the git revert command to create a new commit and undo the changes introduced by the previous commit. These commands are the most commonly used commands in Git, and mastering them will greatly improve your development efficiency. Hope this brief guide has been helpful!

Supongo que te gusta

Origin blog.csdn.net/Damon_Sandy/article/details/134003800
Recomendado
Clasificación