Git fundamentals and frequently used commands

Source: Internet
Author: User
Tags using git

Usually use two version number control software SVN and Git, in all fairness, assuming purely own use, then absolute git more suitable, local library, remote library, offline work, powerful and flexible branch, the famous GitHub, these are the reasons to choose Git. Remember when you first approached Git, feel git is so powerful, plus it is written by the famous Linus, so spend a lot of time to read all kinds of information, but later those less often used commands and functions only stay on the level of knowing and understanding. Git is a tool, a tool that is written to meet a need, to make good use of the tools. Of course, to do good and useBe sure to understand the ideas that Git advocates, and how it's implemented inside.。

Git getting started here's a very easy Git tutorial written by Liaoche, and I spent an afternoon doing the tutorial and then started using Git.

Git principle git is essentially a set ofcontent addressed file system。 Internally, Git is a simple key-value data store. It agrees to insert arbitrary types of content and returns a key value that can be taken out of the content at any time. These objects are compressed and are uniquely labeled with their own SHA-1 hashes. It agrees to insert arbitrary types of content and returns a key value that can be taken out of the content at any time.

Git mainly consists of 3 classes of objects:Blog (store file data), tree (similar to folder), Commit。 Each Git commit produces a commit object and updates all the tree objects associated with the modified file. Multiple tree objects Together record information that includes all the Blob objects for the entire project, andmake Up (DAG) directed acyclic graph。 So at any point in time, regardless of the circumstances, the only root node tree associated with the commit object is able to traverse all the files in this commit state to find the entire project.

Git is able to do this in two basic waysdata transfer across two warehouses: based on HTTP protocol, and file://, ssh://, git://and other intelligent transfer protocols。

Git Plugin

Good IDE basically integrates git plugin, the sexiest editor Sublime also has third party git plugin. These plug-ins are basically a good menu option for the most commonly used git features, so you can also learn about the commands and features you use most often in Git's everyday use by using these plugins.


Git Usage Note

Assuming you are using a git plugin in the IDE, do not operate in the command line (shell), and there are two processes at the same time for a git library that can cause confusing problems . So assuming that the software's Git plugin has no functionality to find or operate, it is recommended to turn off the IDE first and then run the git command in the command line form.


Git often uses commands

This does not need to be deliberately to remember, but to have a general understanding of the time to see Help or Google.

git help <command> # Displays the specified command helpgit config--global user.name "Your name" git config--global user.email "yo                    ur email "# Change and commit git status # View workspace status git add <file> # commits the specified file changes to the local staging area git Add. # All the changed files are staging area, do not contain delete, "." That means the regular match all characters git add--all # commits all workspace changes to staging area, containing the deleted files git add-a # ditto git commit-m "comm                 Ents "# Submit the contents of the staging area to the local library, plus a note git commit <file> # Commit staging Area The specified file git commit. # Submit Staging Area All files git commit-a # git add, git rm and git commit are all merged together, not including new file git Commit-am "comments" # Ibid + Plus             Enter comment # undo and redo Git checkout-<file> # Discard workspace To specify file changes git checkoout.              # Discard Workspace All changes git reset <file> # Restore the specified files from staging area to workspace git reset--.  # Restore all files from staging area to workspace git reset--hard # Restores the state of a recent commit, all changes to the workspace are discarded # view commit git show # show a commit content git show $idgit Loggit Log <file> # View this file every time you submit a record git log-p <file>   # See the Diffgit of each specific change log-p-2 # See the Diffgit Log--stat # for the details of the recent two changes # View submission Statistics # diff git diff <file> # Compare the difference between the current file and the staging area file git diff < $id 1> < $id 2> # Compare two commits between Git diff <branch1> <branch2> # between two branches compared to Git diff--staged # Compare staging area and version number library difference git diff--stat # only                    Compare statistics # about version number git tag #查看版本号git tag [name] #创建版本号git tag-d [name] #删除版本号git tag-r #查看远程版本号git push origin [name] #创建远程版本号 (local version number push to Far # About branching git branch <new_branch> # Creating a new branch git checkout <branch> # switch to a branch git checkout                       -B <new_branch> # Create new branch and switch past git branch-v # View each branch last commit information git branch-r # View Remote Branch git branch--merged # View a branch that has been merged into the current branch git branch--no-merged # view has not been merged into the current branch branch G             It checkout $id       # Submit A history to checkout out, no branch information, switch to other branches will take the initiative to delete git checkout $id b <new_branch> # put a history submitted checkout out, create a branch git bran ch-d <branch> # Delete a branch git branch-d <branch> # Force a branch to be deleted (mandatory when the branch is not merged) # about remote warehouses Git remote add Origin <remote> # Join the long-range repository git remote-v # View remote server address and warehouse name git remote show            Origin # View Remote server warehouse status git remote RM <repository> # Delete Remote repository Git push-u origin master # Client commits Git push-u Origin develop # for the first time to commit the local develop branch to the remote develop branch, and track# tracks the remote library and local repository git branch--set-upst Ream Master Origin/mastergit Branch--set-upstream Develop Origin/develop

"Address" http://blog.csdn.net/thisinnocence

Git fundamentals and frequently used 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.