Git learning Summary (1): git learning Summary
. List of common Git commands
1. Create a code library
# Create a Git code library in the current directory
$ Git init
# Create a directory and initialize it as a Git code library
$ Git init [project name]
# Download a project and its entire code history
$ Git clone [url]
Ii. Configuration
Git settings are not set to. gitconfig. You can set them in the user's main directory (global configuration) or in the project (project configuration ).
# Display the current Git Configuration
$ Git config -- list
# Edit the Git configuration file
$ Git config-e [-- global]
# Set the user information for code submission
$ Git config user. name
$ Git congig user. email
3. Add/delete files
# Add a specified file to the temporary storage Zone
$ Git add [file1] [file2]...
# Add a specified directory to the temporary storage area, including subdirectories
$ Git add [dirname]
# Add all files in the current directory to the temporary storage Zone
$ Git add
# Confirmation is required before each change is added.
# Multiple changes to the same file can be submitted in multiple stages
$ Git add-p
# Delete the workspace file and put it in the temporary storage zone.
$ Git rm [file1] [file2]...
# Stop tracing a specified file, but the file will be retained in the Workspace
$ Git rm -- cache [file]
# Change the file name and put the change in the temporary storage area
$ Git mv [filename-original] [filename-renamed]
4. Code submission
# Submit the temporary storage area to the local warehouse area
$ Git commit-m [message]
# Submit a specified file for the temporary storage area to the local warehouse area
$ Git commit [file1] [file2]...-m [message]
# Submit the changes in the workspace since the previous commit and directly go to the local warehouse
$ Git commit-
# Display all diff information when submitting
$ Git commit-v
# Use a new commit instead of the previous commit
# If the Code does not change, it is used to modify the commit information of the previous commit.
$ Git commit -- amend-m [message]
# Redo the previous commit and include new changes to the specified file
$ Git commit -- amend [file1] [file2]...
V. Branch
# List all remote branches
$ Git branch-r
# List all local branches and remote branches
$ Git branch-
# Create a new branch, but remain in the current Branch
$ Git branch [branch-name]
# Create a new branch and switch to it
$ Git checkout-B [branch]
# Create a new branch pointing to the specified commit
$ Git branch [branch] [commit]
# Switch to the specified branch and update the Workspace
$ Git checkout [branch-name]
# Switch to the previous Branch
$ Git checkout-
# Merge the specified branch to the current Branch
$ Git merge [branch]
# Select a commit and merge it to the current Branch
$ Git cherry-pick [commit]
# Create a new branch and establish a tracking relationship with the developed Remote Branch
$ Git branch -- track [branch] [remote-branch]
# Establish a tracing relationship between an existing branch and a specified remote Branch
$ Git branch -- set-upstream [branch] [remote-branch]
# Deleting a branch
$ Git branch-d [branch-name]
# Deleting a remote Branch
$ Git push origin -- delete [branch-name]
$ Git branch-dr [remote/branch]
Vi. Labels
# List all tags
$ Git tag
# Create a tag at the current commit
$ Git tag [tag]
# Create a tag at the specified commit
$ Git tag [tag] [commit]
# Deleting a local tag
$ Git tag-d [tag]
# Deleting a remote tag
$ Git push origin: refs/tags/[tagname]
# Viewing tag Information
$ Git show [tag]
# Submit a specified tag
$ Git push [remote] [tag]
# Submit all tags
$ Git push [remote] -- tags
# Create a branch pointing to a tag
$ Git checkout-B [branch] [tag]
VII. View information
# Display all changed files
$ Git status
# Display the version history of the current Branch
$ Git log
# Display the commit history and the files with each commit change
$ Git log -- stat
# Search submission history based on keywords
$ Git log-S [keyword]
# Display all changes after a commit. Each commit occupies one row.
$ Git log [tag] HEAD -- pretty = format: % s
# Show All changes after a commit. The "Submit description" must meet the search criteria
$ Git log [tag] HEAD -- grep feature
# Display the version history of a file, including renaming the file
$ Git log -- follow [file]
$ Git whatchanged [file]
# Frame each diff related to a specified file
$ Git log-p [file]
# Show the last five submissions
$ Git log-5 -- pretty -- online
# Display all submitted users, sorted by the number of submissions
$ Git commit log-sn
# Display the time when the specified file was modified.
$ Git blame [file]
# Display the differences between the temporary storage zone and the Workspace
$ Git diff
# Display the differences between the temporary storage zone and the previous commit
$ Git diff-cached [file]
# Display the differences between the workspace and the latest commit of the current Branch
$ Git diff HEAD
# Display the differences between two submissions
$ Git diff [first-branch]... [second-branch]
# Display the number of lines of code written today
$ Git diff -- pull stat "@ {0 day ago }"
# Display the original data and content changes submitted for a certain time
$ Git show [commit]
# Display a file that has been submitted for change
$ Git show -- name-only [commit]
# Display the content of a file when a file is submitted
$ Git show [commit]: [filename]
# Display the latest submissions of the current Branch
$ Git reflog
8. Remote Synchronization
# Download all changes to the remote Repository
$ Git fetch [remote]
# Display all remote Repositories
$ Git remote-v
# Display the information of a remote warehouse
$ Git remote show [remote]
# Add a new remote repository and name it
$ Git remote add [shortname] [url]
# Retrieve remote repository changes and merge them with local branches
$ Git pull [remote] [branch]
# Upload a local branch to a remote Branch
$ Git push [remote] [branch]
# Forcibly push the current Branch to a remote warehouse, even if there is a conflict
$ Git push [remote] -- force
# Push all branches to a remote Repository
$ Git push [remote] -- all
9. Undo
# Restore a specified file in the temporary storage area to the Workspace
$ Git checkout [file]
# Restore a specified commit file to the temporary storage area and workspace.
$ Git checkout [commit] [file]
# Restore all files in the temporary storage area to the Workspace
$ Git checkout
# Reset the specified file in the temporary storage area, which is consistent with the previous commit, but the workspace remains unchanged.
$ Git reset [file]
# Reset the temporary storage area and workspace, consistent with the previous commit
$ Git reset -- hard
# Reset the HEAD of the current branch to specify the commit, and reset the temporary storage area and workspace at the same time, consistent with the commit
$ Git reset -- hard [commit]
# Reset the current HEAD to specify the commit, but keep the temporary storage area and workspace unchanged.
$ Git reset -- keep [commit]
# Create a new commit to cancel a specified commit.
# All changes of the latter will be offset by the former and applied to the current branch.
$ Git revert [commit]
# Temporarily remove unsubmitted changes and move them in later
$ Git stash
$ Git stash pop
10. Others
# Generate a compressed package for release
$ Git archive
# Create a new branch that does not contain the submission history package of the original Branch
$ Git checkout -- orphan gh-pages