Usage and interpretation of common Git commands

Source: Internet
Author: User

Usage and interpretation of common Git commands

Common git commands:

Add Add file contents to the index (add the file to the temporary storage area)

Usage:

Save a file to the hold zone: git add file name

Save all files in the current path to the hold zone: git add. (note that the last point is .)

2. bisect Find by binary search the change that introduced a bug (using binary search to quickly locate version errors, although bisect is not widely known because it is not used much, but when you want to know when a good branch gets worse, it will be useful .)

Usage:

Set the first and second versions, one is good, and the other is bad. Use binary search for the intermediate version for compilation to check whether there is a problem. If not, the version is divided into two parts with the previously set bad. If there is an error, the version is divided into two parts with the previously set good.

Git bisect start/bad/good

3. branch List, create, or delete branches (List, create, or delete branches)

Usage:

Git branch without parameters: list existing local branches and add the "*" sign before the current branch.

Git branch-r list remote branches

Git branch-a lists local branches and remote branches

Note that git branch is used to create a new local branch.

Git branch-m |-M oldbranch newbranch rename the branch. If a newbranch name already exists, use-M to rename the branch. Otherwise, use-m to rename the branch.

Git branch-d |-D branchname Delete branchname branch

Git branch-d-r branchname Delete remote branchname branch

4. checkout Checkout a branch or paths to the working tree (check the content from the branch or path to the workspace)

Usage:

Switch to the new branch: git checkout branchName

5. clone Clone a repository into a new directory (clone a repository to a new directory)

Usage:

Download the remote repository to the current path: git clone repository URL

Download the remote repository to a specific path: the path where the git clone repository URL is stored

6. commit Record changes to the repository (submit the change to the warehouse)

Usage:

Submit a file to the branch: git commit-m "comment" File Name

Save all files in the current path to the branch: git commit-m "Comment"

7. diff Show changes between commits, commit and working tree, etc (display submission, working directory changes)

8. fetch Download objects and refs from another repository (Download objects from another repository)

9. grep Print lines matching a pattern (fuzzy query)

10. init Create an empty Git repository or reinitialize an existing one (Create an empty git repository, or Initialize an existing repository again to generate one. git directory, used to maintain version information)

Usage:

Initialize the repository in the current path: git init

Initialize the repository in other paths: git init repository path

11. log Show commit logs (display submit log)

(Note: the version number in Git is a "40-bit" hash value, while the version number in SVN is an incremental integer)

Usage:

View the modification log of a file: git log File Name

View the modification logs of all files in the current path: git log

View simple log information in one row: git log -- pretty = oneline

View the last N changes: git log-N (N is an integer)

12. merge Join two or more development histories together (combine the two development processes)

13. mv Move or rename a file, a directory, or a symlink (Move, rename a file, directory, or link)

14. pull Fetch from and integrate with another repository or a local branch (obtain and merge from another warehouse or branch to local warehouse)

15. push Update remote refs along with associated objects (Update local repository to remote repository)

16. rebase Forward-port local commits to the updated upstream head (Sequentially regenerate a series of commits so they can be applied directly to the head node to generate a series of submissions in an orderly manner, and use the header node)

17. reset Reset current HEAD to the specified state (to restore the version to a specific state, we recommend that you add the -- hard parameter, git supports unlimited regret)

Usage:

Roll back to the previous version: git reset -- hard HEAD ^

Roll back to the previous version: git reset -- hard HEAD ^

Roll back to the previous N versions: git reset -- hard HEAD ~ N (N is an integer)

Roll back to any version: git reset -- hard version number (the version number must be 7 bits)

18. rm Remove files from the working tree and from the index (Remove the file from the temporary storage area. After deletion, you must perform the commit operation to synchronize the file to the version library)

Usage: git rm file name

19. show Show various types of objects (display different objects)

Usage:

20. status Show the working tree status (display the workspace File status)

Usage:

View the status of a file: git status File Name

View the status of all files in the current path: git status

21. tag Create, list, delete or verify a tag object signed with GPG (Create, list, delete or modify tags)

Usage: git tag-a v1.0-m 'version 1.0'

22. help view the git instruction help manual

Usage:

View Common commands: git help

How to view other commands: git help other commands

23. config configure git-related information (the. git/config file is modified)

Usage:

Configuration Username: git config "user. name" username (used to track modification Records)

Configuration mailbox: git config "user. email" Mailbox (used for communication between developers)

View configuration information: git config-l

Edit the configuration information: git config-e (use vim to edit: wq to exit the vim editor)

SET command alias: git config alias. alias original command name

Set the alias with the parameter command: git config alias. alias "original command name parameter"

Apply this setting to the entire system: git config -- global

24. reflog view branch reference records (view all version numbers)

Git Tutorials:

GitHub tutorials

Git tag management details

Git branch management

Git remote repository details

Git local Repository (Repository) Details

Git server setup and Client installation

Git Overview

Share practical GitHub tutorials

How to Build and use Git servers in Ubuntu

Git details: click here
Git: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.