git Command Usage Summary

Source: Internet
Author: User
Tags git commands

one. Branch
$ git branch//view local branch
* Master
$ git branch-r//View Remote branch
Origin/head-Origin/removal
Origin/master
Origin/removal
$ git checkout-b removal origin/removal//new local branch and switch to remote branch

$git branch-d//Delete a branch

two. Cloning
$ git clone~/workspace/study/tmp.git//clone local repository

three. Patches
$ git format-patch-1 de4f9255d//generates patches, each of which represents the generation of several patches and a commit ID
$ git apply--check//check if patch can be hit
$ git apply001.patch
$ git am 001.patch//apply &mail

four. Rebase
1. Create a repository: $ git--bare inittmp.git
$ ls tmp.git
branches Config description gitk.cache HEAD Hooks info Objects Refs
2. Clone this repository: clone-1$git Clone ~/workspace/study/tmp.git
Clone-1$ ls
tmp
3. Clone one more:clone-2$ git clone ~/workspace/study/tmp.git
Clone-2$ ls
tmp
4. Modify the file maintainers in clone-1 , Commit, and then Pushorigin Master to the remote master branch
5. Modify the file in the clone-2 maintainers, and commit, at this time push will fail, need to rebase operation and then push, as follows:
$ git Fetchorigin
$ git rebaseorigin/master
$ git pushorigin //Upstream BranchOptional , default is the remote branch corresponding to the local branch
$ GITK//graphical view of git log
650) this.width=650; "src=" http://s10.sinaimg.cn/mw690/002Hmwlzgy6LUhOFw3D99&690 "Name=" Image_operate_ 58451410249918679 "alt=" Git commands use summary "title=" git command summary "/>

Figure 1-1
FancyFigure 1-1, the difference between rebase and gitpull (merge) can be fully seen by comparing the historical information above and below the red line, clone ... The information that is submitted on the Clone-1 branch, Clone2 ... is clone-2 on the submission, no matter which branch first push into Originmaster, after the submitter, first Rebaseorigin/master, and then push, forming a red line above the commit history, very clear, based on only one main line.

6. Precautions:
Modify a file, if you modify a unified place, rebase will conflict, even if you feel that the same line is not modified, but the context of the changes will be considered conflicting.

Five. Git log/gitk
$ git log--author= "Somebody"//View commit history by author named Somebody
$ git log < file name >/< directory name >//View commit history for a file/directory

Six. Git diff

$ gitdiff (1)
$ git diff--cached (2)
$ git diffhead (3)

1. Changes in the working tree isn't yet staged for the nextcommit.
displays files that have been modified in the current directory but have not yet been cached (git add added to index).
2. Changes between the index and your last commit; What are wouldbe committing if you run "git commit" without "-a" option.
changes between the current index and the previous commit; it's the next commit you'll commit, assuming you're not in the Gitcommit plus-a option (-a means that automatically commits all modified or deleted files)
3. Changes inthe working tree since your last commits; what are would becommitting if you run "git commit-a"
from the last commit, the changes in the current directory (regardless of whether the modified file is cached or not, will be listed)


Comparing with arbitrarycommits--to compare any modifications between commits
$ git difftest (1)
$ git diff HEAD--./test (2)
$ git diff head^head (3)

1. Instead of using the tip of the branch, compare with Thetip of "test" branch.
Not compared to the current branch, but compared to test branch
2. Instead of comparing with the tip of "test" branch, compare withthe tip of the current branch, but limit the comparison To the file "test".
Compares the./test file in the previous commit of the current branch and the modification of the./test file under the current directory
3. Compare the changes between the previous commit and the last commit.

Comparison between comparing Branches--branch

$ git diff topicmaster (1)
$ git diff topic. Master (2)
$ git diff topic...master (3)

1. Changes between the tips of the topic and the masterbranches.
Compare the differences between the topic branch and the master branch
2. Same as above.
Ditto.
3. Changes that occurred in the master branch since when the Topicbranch is started off it.
What modifications are made to the topic after comparing the topic branch from master

For more git diff examples, refer to Git diff--help

Seven. Git rm--cache//DELETE from index only, do not delete local file
Eight. Git reset head^ back up a separate file, if you have committed a commit, but want to remove a file from this commit, you can return the file separately
Nine. Back up the file, with Git status View, displayed as has changed, no add to index, if you want to undo the change, you can:
Git checkout


Nine. git rebase head^--onto v3.18-rc1

will head^ rebase to v3.18-rc1 , head^ after the commit will be based on v3.18-rc1 .

This article is from the "Blue Moon Career Life" blog, please be sure to keep this source http://lyrazhang.blog.51cto.com/8093569/1583977

git Command Usage 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.