Git Common Commands Summary

Source: Internet
Author: User

Objective

Study for a while git, feel the operation is git commit,git pull, git push, git add,git submodule and so on, do a summary, relatively clear.

Create

To copy a warehouse that you have created:

$ git clone ssh://[email protected]/blog.git

To create a new local repository:

$ git init
Local modifications

Show modified files under work path:

$ git status

Display differs from the last commit version file:

$ git diff

Add all current changes to the next commit:

$ git add

To add changes to a file in the next commit:

$ git add-p <file>

Commit all local modifications:

$ git commit-a

Changes that were marked before committing:

$ git commit

Additional Message submissions:

$ git commit-m ' message here '

Commit, and set the submission time to a previous date:

git commit--date= "' Date--date= ' N day ago '"-am "commit Message"

Modify last commit: Do not modify the published submission record!

$ git commit--amend

Move uncommitted changes in the current branch to another branch

git stashgit checkout branch2git stash Pop
Search

Find text content from all files in the current directory:

$ git grep "Hello"

To search for text in a version:

$ git grep "Hello" v2.5
Submit History

From the latest submission, show all commit records (display hash, author information, submitted title and time):

$ git log

Show all commits (only the submitted hash and message are shown):

$ git log--oneline

Show all submissions for a user:

$ git log--author= "username"

Show all changes to a file:

$ git log-p <file>

Who, at what time, modified what content of the file:

$ git blame <file>
Branches and labels

List all the branches:

$ git Branch

To switch branches:

$ git checkout <branch>

To create and switch to a new branch:

$ git checkout-b <branch>

To create a new branch based on the current branch:

$ git Branch <new-branch>

Create a new traceable branch based on a remote branch:

$ git branch--track <new-branch> <remote-branch>

To delete a local branch:

$ git branch-d <branch>

To label the current version:

$ git tag <tag-name>
Update and release

List the remote side of the current configuration:

$ git remote-v

Displays information from the remote side:

$ git remote show <remote>

To add a new remote end:

$ git remote add <remote> <url>

Download the remote end version, but do not merge into the head:

$ git fetch <remote>

Download the remote end version and automatically merge with the head version:

$ git remote pull <remote> <url>

To merge the remote end version into the local version:

$ Git pull Origin Master

To publish a local version to the remote side:

$ git push remote <remote> <branch>

To delete a remote-side branch:

$ git push <remote>:<branch> (since git v1.5.0) or git push <remote>--delete <branch> (since git v1 .7.0)

Publish Tags:

$ git push--tags
Merging and resetting

To merge the branches into the current head:

$ git Merge <branch>

Resets the current head version to the branch: Do not reset the published submission!

$ git rebase <branch>

To exit the Reset:

$ git rebase--abort

Continue resetting after resolving conflicts:

$ git rebase--continue

Resolve conflicts using the configured merge tool:

$ git Mergetool

After manually resolving conflicts in the editor, mark files as resolved conflicts

$ git add <resolved-file>$ git rm <resolved-file>
Revoke

Discard all changes under the working directory:

$ git reset--hard HEAD

Remove all files from the cache (i.e. undo last git Add):

$ git reset HEAD

Discard all local modifications to a file:

$ git checkout HEAD <file>

Reset a commit (by creating a completely different new submission)

$ git revert <commit>

Resets the head to the specified version and discards all modifications after that version:

$ git reset--hard <commit>

Resets the head to the last committed version and marks the subsequent modifications as not added to the buffer:

$ git reset <commit>

Reset the head to the last committed version and leave uncommitted local modifications:

$ git reset--keep <commit>
The use of Git submodule

In the development process, there are often some common parts of the hope to be extracted into a public library to provide other projects to use, so that the git git submodule command.

Add to

To add submodule to the current project, the command is as follows:

Git submodule Add warehouse address path

For example:

git submodule add helloworld.gitgit commit-m "add submodules helloworld.git"

Other people collaborate

git clone/path/to/repos/helloworld_parent.gitgit submodule initgit submodule Update

Removed from

1. Delete the git cache and the physical folder

2. Delete the contents of the. Gitmodules (or the entire file) because this example has only two submodules, delete the file directly

3. Delete the. git/config submodule Configuration source file

4. Submit Changes

Git Common Commands Summary

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.