Git Common command to organize _linux shell

Source: Internet
Author: User
Tags commit rollback git clone

Objective

Here does not introduce git, table a see the command line is afraid, commonly used commands are these, basically meet more than 99% of the project needs, very practical.

Body

  First, Common git command

1.1 Git clone <url> [<directory>]

From remote library clone code to local, directory is used to specify a new directory name

1.2 Git status

Check the local state to see the current branch, new or modified files

1.3 Git checkout <file>

Restore any changes made to a file, or "Git checkout." Restore all modifications

1.4 git Add <file>

Add files to the cache and track new files. You can also "git Add." To add all files to the cache

1.5 git commit-m "commit message"

Submit code to the local code base, it is highly recommended to do a small function to commit once, multiple commit to replace a large commit, but also facilitate subsequent code merging and review.

1.6 Git push

Synchronize the local library code to the remote library. (A push failure will refer specifically to code merging)

1.7 Git Branch

List available branches, git branch-a list all branches of local and remote libraries

1.8 Git Checkout <branch>

Toggle Branch

1.9 git log [-<number>]

View local commit record, number can limit log display bar

1.10 git diff [<file>]

Compare current file and registers file differences

1.11 git Pull

Extract update code from remote Library to local

Second, code revocation

2.1 Undo Local No Add, no commit code

Git checkout <file> undo a single file, or "Git checkout." Undo all local modifications.

2.2 Undo locally already add, but not commit code

Git reset <file> undo a single file, git reset undo All

2.3 Undo code that has been commit locally but not pushed

git reset--hard head~1 undo the last commit and rollback code to the last commit code, and notice that the code is discarded. (without--hard you can only undo a commit, not rollback code)

2.4 Undo already commit and push code

git revert <commit id>

2.5 Modify already-commit annotation content

Git commit--amend, generally will open with Vim, modified: Wq exit can.

Merging with branch code

Scenario: If Git pull fails or if a remote library is known to be updated, pay attention to the local commit before rebase the operation.

3.1 Git pull--rebase

Extract the update code from the remote library to the local and try to merge the code. Unlike the merge, there will be no new commit records, and the merging of code needs to be very careful not to lose the code of other small partners!

3.2 git add <file>

Encounter conflict resolution conflict, after the completion of the solution git add

3.3 Git rebase--continue

All conflicts are resolved and add to continue after rebase, do not commit, you may need multiple continue and add operations, until all merged.

3.4 Git push

Synchronizes the local code base code to the remote library.

Four, different branch code merge

Scenario: Merge code from develop branch (development) to Master Branch (production)

4.1 Git cherry-pick <commit id>

Apply a commit modification of another branch to the current branch. A commit ID supports a cross branch, a short commit ID (top 8 bits, for example, 247d27c6) and, of course, is also supported for the same branch.

4.2 Git add <file>

Encounter conflict resolution conflict, after the completion of the solution git add

4.3 git rebase--continue

All conflicts are resolved and add to continue after rebase, do not commit, you may need multiple continue and add operations, until all merged.

4.4 Git push

Synchronizes the local code base code to the remote library.

V. Code staging

Scenario: Feature unfinished and not commit, but need to restore code to last commit (for example, Emergency bug fix)

5.1 git Stash

Staging the uncommitted code and restoring all modifications

5.2 Git stash Pop

Restore the last Stash code

Vi. Other

6.1 Android

Android Studio's own version management is very handy, and it's easy to switch branches, compare changes, and merge submitting code.

6.2 IOS

You can use XCode's own version management detection contrast, commit to local, and then merge from the command line.

There are also many students with Sourcetree

6.3 Git Official Chinese version

Https://git-scm.com/book/zh

The above is the collation of common commands for Git friends who need to refer to the following.

Related Article

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.