Common git commands and git commands

Source: Internet
Author: User
Tags file diff git commands

Common git commands and git commands
Common Git commands

View, add, submit, delete, retrieve, and reset the modified File

Git help <command> # display command help

Git show # display the submitted content git show $ id

Git co -- <file> # discard workspace Modification

Git co. # discard workspace Modification

Git add <file> # submit the changes to the work file to the local temporary storage area.

Git add. # submit all modified work files to the temporary storage Zone

Git rm <file> # delete files from the version Library

Git rm <file> -- cached # delete a file from the version library, but do not delete the file

Git reset <file> # recovering from the temporary storage area to working files

Git reset --. # recovering from the temporary storage area to working files

Git reset -- hard # restore the last submitted status, that is, discard all the modifications made after the previous submission.

Git ci <file>

Git ci.

Git ci-a # merge git add, git rm, git ci, and other operations for git ci-am "some comments"

Git ci -- amend # Modify the last commit record

Git revert <$ id> # restore a submitted state. The restore action also creates a submitted object.

Git revert HEAD # restore the last submitted state

View the file diff

Git diff <file> # compare the differences between the current file and the files in the temporary storage area

Git diff <id1> <id2> # compare the differences between two commits

Git diff <branch>... <branch2> # comparison between two branches

Git diff -- staged # compare the differences between the staging zone and the version Library

Git diff -- cached # compare the differences between the staging zone and version Library

Git diff -- stat # only compare statistics

View submission records

Git log

Git log <file> # view each submission record of the file

Git log-p <file> # view the diff of each detailed Modification

Git log-p-2 # view the diff of the last two detailed changes

Git log -- stat # view submitted statistics

Tig

On Mac, you can use tig instead of diff and log.

Git local branch management

View, switch, create, and delete branches

Git br-r # view remote branches

Git br <new_branch> # create a new branch

Git br-v # view the final submission information of each branch

Git br -- merged # view the branches that have been merged to the current Branch

Git br -- no-merged # view the branches that have not been merged to the current Branch

Git co <branch> # switch to a branch

Git co-B <new_branch> # create a new branch and switch

Git co-B <new_branch> <branch> # create a new new_branch Based on branch

Git co $ id # checkout a historical commit record, but there is no branch information, switch to another branch will be automatically deleted

Git co $ id-B <new_branch> # checkout a historical commit record and create it as a branch

Git br-d <branch> # delete a branch

Git br-D <branch> # force delete a branch (mandatory when unmerged branches are deleted)

Branch merge and rebase

Git merge <branch> # merge branch branches to the current branch

Git merge origin/master -- no-ff # Do not merge Fast-Foward to generate merge commit

Git rebase master <branch> # rebase the master to branch, equivalent:

Git co <branch> & git rebase master & git co master & git merge <branch>

Git Patch Management (convenient for development and synchronization on multiple machines)

Git diff> ../sync. patch # generate patch

Git apply ../sync. patch # patch

Git apply -- check ../sync. patch # test whether the patch is successful

Git Temporary Management

Git stash # temporary storage

Git stash list # list all stash Columns

Git stash apply # restore saved content

Git stash drop # delete a staging area

Git remote branch management (origin is the name of the remote repository)

Git pull # capture updates from all branches of the remote repository and merge them to the local machine

Git pull -- no-ff # capture all branch updates in the remote repository and merge them to the local machine. Do not merge them quickly.

Git fetch origin # capture remote repository updates

Git merge origin/master # merge the remote master branch into the local current Branch

Git co -- track origin/branch # track A remote branch to create a local branch

Git co-B <local_branch> origin/<remote_branch> # create a local branch based on a remote branch.

Git push # push all branches

Git push origin master # push the local master branch to the remote master Branch

Git push-u origin master # push the local master Branch to a remote location (if there is no remote master branch, it is created to initialize the remote repository)

Git push origin <local_branch> # create a remote Branch

Git push origin <local_branch >:< remote_branch> # create a remote Branch

Git push origin: <remote_branch> # first Delete the local branch (git br-d <branch>), and then push to delete the remote branch

Git remote repository Management

Git remote-v # view the remote server address and repository name

Git remote show origin # view the remote server repository status

Git remote add origin git @ github: robbin/robbin_site.git # add a remote repository address

Git remote set-url origin git @ github.com: robbin/robbin_site.git # set the remote repository address (used to modify the remote repository address)

Git remote rm <repository> # delete a remote repository

Create a remote Repository

Git clone -- bare robbin_site robbin_site.git # use a project with a version to create a version-only Repository

Scp-r my_project.git git @ git.csdn.net :~ # Upload a pure repository to the server

Mkdir robbin_site.git & cd robbin_site.git & git -- bare init # create a pure repository on the server

Git remote add origin git @ github.com: robbin/robbin_site.git # Set the remote repository address

Git push-u origin master # first client commit

Git push-u origin develop # submit the local develop branch to the remote develop branch for the first time, and track

Git remote set-head origin master # set the HEAD of the remote warehouse to point to the master Branch

Git branch -- set-upstream master origin/master

Git branch -- set-upstream develop origin/develop # You can also run the command to set the remote and local databases for tracking.

 

Non-original articles

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.