Git basic commands

Source: Internet
Author: User
Tags version control system

Git A beginner 's Notebook Instruction Operation Teaching

Git is a decentralized version control system, from the frame, easy to operate, set, this article is mainly to organize basic operations, remote operation and so on.

Note: The range of Git is too broad, so this is the beginning of the study into the door. :)

Attention to things

by Project/.git/config: (If there is more, can be learned from this)

· Origin (remote) is a version of Repository

· Master (branch) is the local side, the version being modified

It's usually okay not to move to origin, and if you do, git reset--hard can go back to the unmodified state.

Git New Files

· git Add. # Save the information to staging area first, add the new information, the commit will not be included in the.

· Git addfilename

· Git addmodify-file # Modified files, also add. (otherwise commit to add-a)

· Git add-u # only modified files, new files are not added.

· Git add-i # into interactive mode

Git Delete Files

· Git rmfilename

Git Modify the file name and move the catalogue

· Git mvfilename new-filename

Git Status look at the status quo.

· Git status # Look at the current file state

Git Commit

· Git commit

· Git commit-m ' commit message '

· Git commit-a-m ' commit-message ' # commits all the modified files, but the new file will have to add first.

· Git commit-a-v #-V can see which content has been changed in the file,-a commits all modified files

Git produce a new Branch

· Git Branch # lists how many branch are currently

· Git branchnew-branch # generates a new branch (name: New-branch) that, if not specified, will be copied directly from the current branch/master.

· git branchnew-branch Master # generates new branch (New-branch) from master

· git branchnew-branch v1 # new Branch (New-branch) generated by tag (v1)

· git branch-dnew-branch # erase New-branch

· Git branch-dnew-branch # powerful Delete new-branch

· git checkout-b new-branch test # Generates a new branch, and is switched over New-branch

· # with Remote repository

· git branch-r# lists all Repositorybranch

· git branch-a# Lists all branch

Git Checkout Swap Branch

· Git checkoutbranch-name # Swap to Branch-name

· git checkoutmaster # switch to Master

· git checkout-b new-branch Master # Build a new new-branch from master and switch over New-branch

· Git checkout-b newbranch # built on the present environment to create new branch

· Git checkout-bnewbranch Origin # in the base of origin, build new branch

· Git Checkoutfilename # and the original file to Repository

· Git checkouthead. # Checkout All Files out (the last commit version), note that if the file is modified, it will be back to the previous version. (Gitcheckout-f also)

· Git checkoutxxxx. # Checkout All Files out (xxxx commit version, XXXX is the first four code of commit

), note that if the file is modified, it will be the original version.

· Git checkout--* # reverts to the last Commit state (* changed to a file name, you can restore the file only)

Git diff

· What's the difference between git Diffmaster # and Master?

· Git diff--cached # Compare staging area with Ben Repository

· git diff Tag1tag2 # tag1, diff with Tag2

· git difftag1:file1 tag2:file2 # tag1, with Tag2 file1, File2 diff

· git diff # Compare current location with staging area

· Git diff--cached # Compare staging area with Repository difference

· git diff head# the current position and Repository difference

· Git diffnew-branch # The difference between the current position and the branch (New-branch)

· Git diff--stat

Git Tag

· git tag v1ebff # log is a commit ebff810c

Contents of 461ad1924fc422fd1d01db23d858773b

,

The setting is short and good to remember TAG:V1

· git tag Chinese EBFF # tag can also be Chinese, any text can

· git tag-d Chinese # erase tag= Chinese

Git Log

· Git log # will show all the logs

· git log--all # Show all logs (including branch)

· Git log-p # Lists all log and modified files

· git log--stat--summary # Check for more files and rows per version

· Git LogFileName # All the logs in this file

· Git logdirectory # All the logs in this catalogue

· Git log-s ' foo () ' # Log has a string of foo ().

· Git log--no-merges # don't show the merge log

· Git log--since= "2 weeks Ago" # last 2 weeks of log

· Git log--pretty=oneline # show Log Way

· Git Log--pretty=short # show Log Way

· git log--pretty=format: '%h was%an,%ar, message:%s '

· git log--pretty=format: '%h:%s '--graph # There will be simple text graphics, branching, etc.

· git log--pretty=format: '%h:%s '--topo-order--graph # sorted according to main branch

· git log--pretty=format: '%h:%s '--date-order--graph # according to TIME order

Git Show

· Git show ebff# check log is commit ebff810c

Contents of 461ad1924fc422fd1d01db23d858773b

· Git Show v1 # check TAG:V1 modification content

· Git showv1:test.txt # Check TAG:V1 's test.txt file modification content

· Git show head# This version of the modified information

· Git show head^# Previous version of the modified information

· Git showhead^^ # Previous revision of the material

· Git showhead~4 # Previous previous version modified information

Git Reset still original [--mixed |--soft |--hard][]

--mixed

Simply resetting the location of the index without changing any of the things in your work tree (that is, all of the changes in your files are preserved, not labeled as being submitted), and they indicate that nothing has been updated. This is the option of the preset.

--soft

Neither the location of the index nor the contents of the working tree, we only ask that this be a good content (and then become the true content of the submission). This option allows you to reverse the already submitted thing to a state that has been updated but not committed (Updated butnot Check in). It is as if the Git-update-index command has been executed, but there is no git-commit command to perform.

--hard

The contents and the index in the working tree are switched to the specified version location, which means that all the following contents and the contents of the work tree are lost. Therefore, this option should be used with caution, unless you are very sure that you do not want to see those things again.

· Git reset--hard HEAD # to the front

· Git Reset--hard head~3

· Git reset--soft head~3

· git reset Headfilename # goes back to unstaging or untracked from Staging area status (files will not change)

Git grep

· git grep "TE" v1 # Check V1 for "TE" string

· git grep "TE" # Find out if the version has a "TE" string

Git Stash Temporary

· Git stash # drops into the storage area

· Git stash list# lists all the staging areas

· Git stash pop# take out the latest pen and remove it.

· Git stashapply # Take out the latest stash temporary information. But stash does not remove the information

· Git stashclear # Get the stash out of the clear

Git Merge Merge

· git merge

· Git mergemaster

· Git mergenew-branch

· The following download is from: Ihower Git Version control system (2) Open Branch Branch and operate remote repo.

X

· Straight merge mode, all of the merged branch commits Records plus a merge-commit will have two parents lines, and all commit logs will be retained.

· Squashed commit is compressed into only one merge-commit, and there will be no merged log. This is the case with the SVN merge.

· Cherry-pick only merge the specified commit

· Rebase the Branch Branch: Find the common ancestor of the two branch to be merged, then commit to the branch of the merge and then commit again with the current branch. This method is only suitable for local branch that have not yet been shared with others, because it is the same as cutting down the re-training commit log.

Instruction Operation

· Git merge # Merges another branch, and if no conflict conflict is directly commit. If you need to resolve the conflict, you'll have one more commit.

· git merge--squash # merges another branch commit into a pen, which is especially suitable for fixes bugs or new feature that need to be tested, leaving only the results. The merger will not help you commit first.

· Git Cherry-pick 321d76f

# merge only one specific

Commit

。 If you want to merge multiple, you can add the-n directive will not first help you commit, this can be more pick a few to merge the commit, and then git commit.

Git blame

· Git blamefilename # All the commit records for this file

Git files that have been erased

· Git ls-files-d # view erased files

· Git ls-files-d | Xargs git Checkout--# to erase files

Git Protect

· Git GC # PRE-and post-collation differences can be seen by: Git count-objects.

· Git fsck--full

Git revert Information is also original

· Git Reverthead # Back to the state of the previous commit

· Git reverthead^ # Go back to the previous commit state

· git reset Headfilename # goes back to unstaging or untracked from Staging area status (files will not change)

· Git checkoutfilename # unstaging back to the original Repository file (before the file changes back)

The following relate to the remote Repository

Git Remote Protecting remote Files

· Git remote

· git remote addnew-branch http://git.example.com.tw/project.git # Add Remote Repository Branch (Origin->project)

· Git remoteshow # show now how many Repository

· git Remote Rmnew-branch # Erase

· git remoteupdate # Update all Repository branch

· git branch-r# lists all Repositorybranch

Crawl  Swap Repository the branch

· Git fetchorigin

· git checkout--track-b reps-branch origin/reps-branch # crawl Reps-branch and set this branch in local Reps-branch

Erase Repository the branch

· Git pushorigin:heads/reps-branch

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