Common git commands

Source: Internet
Author: User
Tags file diff git commands

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

Git help # display Command help

Git show # display the submitted content git show $ ID

Git co -- # discard workspace Modification

Git Co. # discard workspace Modification

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

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

Git RM # delete files from the version Library

Git Rm -- cached # delete a file from the version library, but do not delete the file

Git reset # 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 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 itself also creates a submitted object.

Git revert head # restore the last submitted state

View the file diff

Git diff # compare the differences between the current file and the files in the temporary storage zone git diff

Git diff <ID> # compare the differences between two commits

Git diff .. # 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 # view each commit record of the file

Git log-P # 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

Git local branch management

View, switch, create, and delete branches

Git Br-r # view remote branches

Git BR # 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 # switch to a branch

Git co-B # create a new branch and switch it over

Git co-B # 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 # checkout a historical commit record and create a branch

Git Br-D # delete a branch

Git Br-D # force delete a branch (mandatory when unmerged branch is deleted)

Branch merge and rebase

Git merge # 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 # rebase the master to branch, equivalent to: git Co & git rebase master & git Co master & git merge

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

Git diff <../Sync. Patch # generate a 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

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 origin/# create a local branch based on a remote branch, with the same functions as above

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 # create a remote branch. The origin is the name of the remote repository.

Git push origin: # create a remote Branch

Git push origin: # first Delete the local branch (GIT Br-d), 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 [email protected] GitHub: Robbin/robbin_site.git # add remote repository address

Git remote set-URL origin [email protected] github.com: Robbin/robbin_site.git # Set the remote repository address (used to modify the remote repository address) git remote RM # Delete the 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 [email protected] 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 [email protected] 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

You can also set the remote and local databases for tracking.

Git Branch -- Set-upstream master origin/Master

Git 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.