List of common Git commands and git commands

Source: Internet
Author: User
Tags git commands

List of common Git commands and git commands
Illustration

Workspace: Workspace Index/Stage: temporary storage area Repository: warehouse area (or local warehouse) Remote: Remote warehouse
Create a code library Git init (create a Git code library in the current directory)Git init project-name (create a directory and initialize it as a Git code library)Git clone url (download a project and its entire code history) Configuration Git config -- list (display the current Git configuration)

Git config-e [-- global] (edit Git configuration file)

Git config [-- global] user. name "[name]" sets the user name

Git config [-- global] user. email "[email address]" sets the user's email address Add/delete files Git add [file1] [file2]... (add the specified file to the temporary storage zone) git add. (add all files in the current directory to the temporary storage zone)Git add [dir] (add the specified directory to the temporary storage area, including subdirectories)Git add-p (confirmation is required before each change is added
Multiple changes to the same file can be submitted in multiple stages)Git rm [file1] [file2]... (delete the workspace file and put it in the temporary storage zone)Git rm -- cached [file] (stop tracing the specified file, but the file will be kept in the workspace)Git mv [file-original] [file-renamed] (rename the file and put it in the temporary storage area)
Code submission Git commit-m [message] (submit the temporary storage area to the warehouse store area)Git commit [file1] [file2]...-m [message] (submit the specified file in the temporary storage area to the warehouse area)Git commit-a (submit the changes in the workspace since the previous commit, directly to the warehouse)Git commit-v (all diff information is displayed upon submission)Git commit -- amend-m [message] (use a new commit instead of the previous commit. If the Code does not change, it is used to rewrite the commit information of the previous commit)Git commit -- amend [file1] [file2]... (redo the previous commit and include new changes to the specified file) Branch Git branch (list all local branches)Git branch-r (list all remote branches)Git branch-a (list all local branches and remote branches)Git branch [branch-name] (Create a new branch, but still stay in the current branch)Git checkout-B [branch] (Create a new branch and switch to it)Git branch [branch] [commit] (Create a new branch pointing to the specified commit)Git branch -- track [branch] [remote-branch] (create a new branch and establish a tracing relationship with the specified remote branch)Git checkout [branch-name] (switch to the specified branch and update the workspace)

Git checkout-(switch to the previous Branch)

Git branch -- set-upstream [branch] [remote-branch] (establishes a tracing relationship between an existing branch and a specified remote branch)

Git merge [branch] (merge the specified branch to the current branch)Git cherry-pick [commit] (select a commit and merge it into the current Branch)Git branch-d [branch-name] (delete branch) delete remote branch
git push origin --delete [branch-name]git branch -dr [remote/branch]
Tag Git tag (list all tags)Git tag [tag] (Create a tag at the current commit)Git tag [tag] [commit] (Create a tag in the specified commit)Git tag-d [tag] (delete local tag)Git push origin: refs/tags/[tagName] (delete remote tag)Git show [tag] (view tag Information)Git push [remote] [tag] (submit the specified tag)Git push [remote] -- tags (submit all tags)Git checkout-B [branch] [tag] (Create a branch and point to a tag) View information Git status (displays changed files)Git log (display the version history of the current Branch)Git log -- stat (displays the commit history and files changed each time the commit is committed)Git log-S [keyword] (search submission history, based on keywords)Git log [tag] HEAD -- pretty = format: % s (display all changes after a commit, each of which occupies one row)Git log [tag] HEAD -- grep feature (show all changes after a commit, its "Submit description" must meet the search criteria) shows the version history of a file, including file renaming
git log --follow [file]git whatchanged [file]
Git log-p [file] (displays each diff related to a specified file)Git log-5 -- pretty -- oneline (displays the last five commits)Git commit log-sn (displays all submitted users, sorted by the number of submissions)Git blame [file] (display the time when the specified file was modified)Git diff (display the differences between the staging zone and the workspace)Git diff -- cached [file] (display the difference between the temporary storage zone and the previous commit)Git diff HEAD (display the difference between the workspace and the latest commit of the current Branch)Git diff [first-branch]... [second-branch] (displays the differences between two commits)Git diff -- cmdstat "@ {0 day ago}" (shows how many lines of code you have written today)Git show [commit] (displays the metadata and content changes of a certain commit)Git show -- name-only [commit] (displays files with changes in a certain commit)Git show [commit]: [filename] (displays the content of a file during a commit)Git reflog (displays the recent submissions of the current Branch) Remote Synchronization Git fetch [remote] (download all changes to the remote repository)Git remote-v (show all remote repositories)Git remote show [remote] (displays information about a remote repository)Git remote add [shortname] [url] (add a new remote repository and name it)Git pull [remote] [branch] (retrieve remote repository changes and merge them with local branches)Git push [remote] [branch] (upload the specified local branch to the remote repository)Git push [remote] -- force (force push the current Branch to a remote repository, even if there is a conflict)Git push [remote] -- all (push all branches to the remote repository) Undo Git checkout [file] (restore the specified file in the temporary storage area to the workspace)Git checkout [commit] [file] (restore the specified file of a commit to the temporary storage zone and workspace)Git checkout. (restore all files in the temporary storage area to the workspace)Git reset [file] (reset the specified file in the temporary storage area to be consistent with the previous commit, but the workspace remains unchanged)Git reset -- hard (reset the temporary storage zone and workspace, consistent with the previous commit)Git reset [commit] (reset the pointer of the current branch to specify commit, and reset the temporary storage area, but the workspace remains unchanged)Git reset -- hard [commit] (reset the HEAD of the current branch to specify commit, and reset the temporary storage area and workspace, consistent with the specified commit)Git reset -- keep [commit] (reset the current HEAD to specify commit, but keep the temporary storage area and workspace unchanged)Git revert [commit] (Create a New commit to undo the specified commit, and all changes to the latter will be offset by the former and applied to the current Branch) Temporarily remove uncommitted changes, move in later
git stashgit stash pop
Others Git archive (generate a compressed package for release)

Related Article

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.