Common git commands

Source: Internet
Author: User
Tags file diff git commands

One, git configuration alias

GIT commands some commands that are longer or faster, and can command abbreviations, or aliases. If you knock on it, it's git st git status a lot easier, and of course we are very much in favor of this lazy approach.

$ git config--global alias.co checkout$ git config--global alias.ci commit$ git config--global alias.br branch$ git con Fig--global alias.st status$ git config--global alias.ps push$ git config--global alias.pl pull

This configuration is all global variables, for all projects to take effect, to see this configuration file can be in the current user's root directory has a. gitconfig file is a global variable file

$ cat. Gitconfig[user]        name = Sunney        email = [email Protected][alias]        CO = checkout        st = status        br = b Ranch        CI = commit        PS = push        PL = Pull        cl = Clone

Second, view, add, submit, delete, retrieve, reset the modified file

git help <command>  # Show Command helpgit show            # shows the content of a commit git show $id git co  --<file>   # Discard work Area Repair Change git co  .           # Discard Workspace Modify git add <file>      # to commit working file modifications to local staging area git Add.           # Submit all modified work files staging area git rm <file>       # Delete files from repository git rm <file>--cached  # Remove files from repository, but do not delete files git reset <fi le>    # Restore from staging area to working file git reset--.      # Restore from staging area to working file git reset--hard    # Restores the state of the last commit, that is, discard all changes to git ci <file>git ci after the previous commit. Git ci-a           # will git Add, gi T rm and Git CI are all merged together to do git ci-am "some comments" Git ci--amend      # Modify the last commit record git revert < $id >    # Restore the status of a commit, restore The action itself also creates a commit object git revert HEAD     # Restores the state of the last commit

Third, view file diff

git diff <file>     # compare current file and staging area file differences git diffgit diff < $id 1> < $id 2>   # Compare two commits difference git diff < Branch1>, .... <branch2> # Compare Git diff--staged # between two branches compare the   staging area and the repository diff git diff--cached   # Compare the staging area and the repository diff git diff--stat     # just Compare statistical information

Iv. viewing submission Records

git loggit log <file>      # View This file every time you submit a record git log-p <file>   # view Diffgit log-p-2       # See the last two details of the changes The Diffgit log--stat      #查看提交统计信息

V. View, toggle, create, and delete branches

git br-r           # View Remote branch git BR <new_branch> # Create a new branch git br-v           # View each branch last commit information git br--merged     # View the branch that has been merged into the current branch G  It br--no-merged  # View branches that have not been merged into the current branch git Co <branch>     # Switch to a branch git co-b <new_branch> # Create a new branch and switch to Git in the past Co-b <new_branch> <branch>  # Branch Create a new new_branch git co $id          # Checkout A history commit record, but no branching information, Switching to another branch automatically deletes the GIT co $id-b <new_branch>  # Checkout out a history commit record, creating a branch git br-d <branch>  # Delete a branch git b r-d <branch>  # Forcing a branch to be removed (the branch that was not merged is removed when it needs to be forced)

Vi. Branch Merger and Rebase

git merge <branch>               # Merge branch branches into the current branch git merge origin/master--no-ff  # do not fast-foward merge so you can generate a merge commit git rebase master <branch>       # rebase Master to branch, equivalent to: Git co <branch> && git rebase master & & Git Co master && git merge <branch>

Vii. git patch management (easy to develop synchronization on multiple machines)

git diff >: /sync.patch         # Build patch git apply: /sync.patch          # Play patch git apply--check. /sync.patch  #测试补丁能否成功

Viii. git staging Management

git stash                        # staged git stash list                   # column all stashgit stash apply                  # recover staged content git stash drop                   # Delete staging Area

Nine, git remote branch management

Git pull                         # Crawl All branch updates from remote repository and merge to local git pull--no-ff                 # Crawl remote repository All branch updates and merge to local, don't fast-forward merge Git fetch Origin                 # Crawl remote repository update git Merge Origin/master          # merges the remote primary branch into the local current branch git co--track origin/branch     # Track a remote branch to create the appropriate local branch git Co-b <local_ branch> origin/<remote_branch>  # Create local branch based on remote branch, same as above
git push                         # push all branches Git push Origin master           # Push the local landlord branch to the remote main branch Git push-u Origin Master        # pushes the local landlord branch to the remote (if no remote main branch is created for Initialize remote repository Git push Origin <local_branch>   # Create remote Branch, origin is the remote repository name GIT push Origin <local_branch>:<remote _branch>  # Create a remote branch Git push Origin:<remote_branch>  #先删除本地分支 (git br-d <branch>) and then push to delete the remote branch

Ten, git remote warehouse management

git remote-v                    # View remote server address and warehouse name git remote show Origin           # View remote server warehouse status git remote add origin [email protected] Github:r Obbin/robbin_site.git         # Add remote warehouse address git remote set-url origin [email protected] Github.com:robbin/robbin_site.git # Set the remote warehouse address (used to modify the remote warehouse address) git remote rm <repository>       # Delete a repository

Xi. Creating a remote repository

git clone--bare robbin_site robbin_site.git  # Create a version-only warehouse with a versioned project scp-r my_project.git [email protected] git.csdn.net:~<  c1/># upload the repository to the server mkdir robbin_site.git && cd robbin_site.git && git--bare init # Create a pure repository git remote add on the server  Origin [email protected] github.com:robbin/robbin_site.git    # set remote Warehouse address Git push-u Origin master                                      # Client First commit git push -U origin develop  # First commits the local develop branch to the remote develop branch, and track git remote set-head origin master   # Set head of remote warehouse to point to master Branch

You can also command settings to track remote libraries and local libraries

Git branch--set-upstream Master origin/mastergit Branch--set-upstream Develop Origin/develop

 

Common git 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.