Common Git Command commands

Source: Internet
Author: User

In general, the daily use of just remember 6 commands, you can. But skilled use, I am afraid to remember 60~100 a command.

Several special nouns are translated as follows.

    • Workspace: Work Area
    • Index/stage: Staging Area
    • Repository: Warehouse area (or local warehouse)
    • Remote: repository

First, create a new code base
# Create a new Git codebase in the current directory $ git init# create a new directory, initialize it to git code base $ git init [project-name]# download a project and its entire code history $ git clone [url]

Second, the configuration

The settings file for Git is. Gitconfig, which can be in the user's home directory (global configuration) or under the project directory (project configuration).

# show current git config $ git config--list# edit git config file $ git config-e [--globaladdress] "


Third, add/delete files
Add  Rename The file and put this name in staging area $ git mv [file-original] [file-renamed]


Iv. Code Submission
# Commit Staging area to  warehouse area $ git commit-m [message]# commit staging area The specified file to warehouse area $ git commit [file1] [file2] ...-m [message]# submit workspace since last Co Mmit after the change, directly to the warehouse area $ git commit-a# Show all diff information at commit time $ git commit-v# use a new commit, instead of the last commit # If the code does not have any new changes, it is used to overwrite the commit information of the last commit $ git commit--amend-m [message]# redo the last commit and include a new change to the specified file $ git commit--amend ...   


V. Branches


Six, label
# list all  tag$ git tag# new one tag in current commit$ git tag [tag]# new tag in specify commit$ git tag [tag] [commit]# view tag info $ git s How [tag]# commits the specified tag$ git push [remote] [tag]# commits all tag$ git push [remote]--tags# Create a new branch, point to a tag$ git checkout-b [branch] [ Tag


Vii. Viewing information
Status# shows the version history of the current branch $ git log# shows the commit history, and each commit changes the file $ git log--stat# shows the version history of a file, including file  rename $ git log--follow [file]$ git whatchanged [file]# displays the specified file related every time diff$ git log-p [file]# shows who the specified file was at what time modified git blame [file] # Show differences between staging area and workspaces $ git diff# show staging area and the difference of previous commit $ git diff--cached []# show the difference between the workspace and the current branch of the latest commit $ git diff head# show the difference between two commits $ g It diff [First-branch] ... [second-branch]# shows the metadata and content changes of a commit $ git show [commit]# shows a file that has been changed by a commit, git show--name-only [commit]# shows a commit, a file's contents $ git sh ow [commit]:[filename]# shows the last few commits of the current branch $ git reflog


Eight, remote synchronization
# download All changes to the remote repository $ git fetch [remote]# Show all remote warehouses $ git remote-v# display information for a remote repository $ git remote show [remote]# Add a new remote repository and  named  Add [shortname] [url]# Retrieve changes to the remote repository and merge with local branch $ git pull [remote] [branch]# upload locally specified branch to remote warehouse $ git push [remote] [branch]# forcibly pushes the current branch to the remote repository, even if there is a conflict $ git push [remote]--force# pushes all branches to the remote repository $ git push [remote]--all 


Ix. Revocation
# Restore Staging area specified file to workspace $ git checkout [file]# restore a commit file to workspace $ git checkout [commit] [file]# restore all files from last commit to workspace $ git Checko UT. # resets the specified file for staging area, consistent with the last commit, but the workspace is unchanged $ git reset [file]# resets staging area with the workspace, consistent with last commit $ git reset--hard# resets the current branch pointer to the specified commit , while resetting staging area, the workspace does not change $ git reset [commit]# resets the current branch's head for the specified commit, while resetting the staging area and workspace, consistent with the specified commit $ git reset--hard [commit]# Resets the current head to the specified commit, but keeps the staging area and workspace unchanged $ git reset--keep [commit]# creates a new commit that revokes all changes to the specified commit# which will be offset by the former and applied to the current branch $ git revert [commit]

X. Other
# Generate a Zip package available for release $ git archive

Common Git Command commands

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.