tencent cloud

Feedback

Common Commands

Last updated: 2022-02-24 16:54:31

    This document describes the common Git commands.

    Create Repository

    $ git clone >                  # Clone a remote repository
    $ git init                         # Initialize a local repository
    

    Modify and Commit

    $ git status                       # View status
    $ git diff                         # View changes
    $ git add .                        # Track all files with changes
    $ git add                    # Track a specific file
    $ git mv                 # Rename a file
    $ git rm                      # Delete a file
    $ git rm --cached             # Stop tracking a file without deleting it
    $ git commit -m "commit messages"  # Commit all updated files
    $ git commit --amend               # Modify the last change
    

    View Commit History

    $ git log                    # View commit history
    $ git log -p           # View the commit history of a specific file
    $ git blame            # View the commit history of a specific file as a list
    

    Revert

    $ git reset --hard HEAD      # Discard all uncommitted modifications in the working directory
    $ git checkout HEAD    # Discard uncommitted modifications in a specific file
    $ git revert         # Revert to a specific commit
    $ git log --before="1 days"  # Show commits created 1 day ago
    

    Branch and Tag

    $ git branch                   # Show all local branches
    $ git checkout     # Switch to a specific branch and tag
    $ git branch       # Create a new branch
    $ git branch -d        # Delete a local branch
    $ git tag                      # List all local tags
    $ git tag >            # Create a tag based on the latest commit
    $ git tag -d          # Delete a tag
    

    Merge and Rebase

    $ git merge         # Merge a specific branch to the current branch
    $ git rebase        # Rebase a specific branch to the current branch
    

    Remote Operations

    $ git remote -v                   # View remote repository information
    $ git remote show         # View the information of a specific remote repository
    $ git remote add     # Add a remote repository
    $ git fetch               # Fetch code from a remote repository
    $ git pull        # Download code and merge
    $ git push        # Upload code and merge
    $ git push  :\>  # Delete a remote branch or tag
    $ git push --tags                       # Upload all tags
    

    For more information, see the Git Documentation.

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support