Introduction to Git and installation on CentOS

Source: Internet
Author: User
Tags svn update tag name using git version control system git commands

Git is a distributed version control system. As a distributed version control system, there is no concept of the main library in Git, and each copy of the library can be used independently, and any inconsistencies between the two libraries can be merged.

Git was originally distributed version control software created by Linus Benedict Torvalds for more efficient management of Linux kernel development, unlike common version control tools such as CVS and subversion, which do not need server-side software support. Speed and efficiency also have a considerable degree of improvement.


Five basic differences between Git and SVN

Git is distributed, and SVN is not

Git stores content as metadata, and SVN is file-based

Git branch differs from SVN's branch

Git does not have a global version number, and SVN has

Git has better content integrity than SVN


First, install the dependent software

Yum install zlib zlib-devel OpenSSL openssl-devel libcurl-devel gcc gcc-c++-y


Second, download and install Git

Download git from http://git-scm.com/download or use the wget command to get

$ wget http://distfiles.macports.org/git/git-2.1.1.tar.gz


Switch to its directory after decompression

$ tar xvfj git-1.7.6.tar.bz2

$ CD git-1.7.6

Install using the default configuration, and if you want to modify the configuration, you can use the./configure--help to get help

$./configure

$ make

$ make Install


Third, initialize the configuration

Git is installed by default in/usr/local/bin, and can be verified after installation.

$ whereis git to view the installation path

Git:/usr/local/bin/git


$ git--version view version

git version 1.7.6


$ git--help view Help information


Iv. git commands

1, Git command First knowledge

Before formally introducing GIT commands, let's introduce Git's basic commands and actions, and have a general understanding of GIT commands.


Example: initialization from a git repository, usually in two ways:

1) git clone: This is a simpler way to initialize, when you already have a remote git repository, you only need to clone a copy locally

Example: Git clone git://github.com/someone/some_project.git some_project


The above command is to fully clone the remote repository of the URL address ' git://github.com/someone/some_project.git ' to the local some_project directory



2) git init and git remote: This is a little more complicated, and when you create a working directory locally, you can go to the directory and initialize it with the ' git init ' command, and Git will then version the files in that directory, At this point if you need to put it on a remote server, you can create a directory on the remote server and record the accessible URL, you can use the ' Git remote add ' command to add a remote server side,

Example: Git remote add Origin git://github.com/someone/another_project.git


The above command will add the URL address ' git://github.com/someone/another_project.git ', the name is origin of the remote server, in the future to commit the code only need to use the Origin alias



2. Common Git Commands

1) Remote Warehouse related commands

Checkout warehouse: $ git clone git://github.com/jquery/jquery.git


View remote repositories: $ git remote-v


Add remote repository: $ git remote add [name] [url]


Delete Remote repository: $ git remote RM [name]


Modify remote repository: $ git remote set-url--push [name] [Newurl]


Pull remote repository: $ git fetch [remotename] [Localbranchname]


Push remote repository: $ git push [remotename] [Localbranchname]



* If you want to submit a local branch test to the remote repository as the master branch of the remote repository, or as another branch called Test, as follows:

$git Push Origin Test:master//submit local Test branch as remote Master Branch


$git Push Origin test:test//submit local test branch as remote Test branch



2) Branch (branch) operation related commands


View local branch: $ git Branch


View Remote branch: $ git branch-r


Create local branch: $ git branch [name]----Note that the new branch will not automatically switch to the current branch after it is created


Switch Branch: $ git checkout [name]


Create a new branch and switch immediately to the new branch: $ git checkout-b [name]


Delete Branch: $ git branch-d [name]-----D option can only delete branches that have already joined the merge and cannot be deleted for branches that do not have a merge. If you want to forcibly delete a branch, you can use the-D option


Merge branch: git merge [name]----Merge the branch with the name [name] with the current branch


Create a remote branch (local branch push to remote): $ Git push origin [name]


Delete Remote branch: git push origin:heads/[name] or $ gitpush origin: [Name]



* Create an empty branch: (Before executing the command remember to submit your current branch of the changes, otherwise it will be forced to delete the clean without regret)

$git symbolic-ref HEAD Refs/heads/[name]


$rm. Git/index


$git CLEAN-FDX



3) version (tag) operation related commands


View version: $ git tag


Create version: $ git tag [name]


Delete version: $ git tag-d [name]


View remote version: $ git tag-r


Create a remote version (local version push to remote): $ Git push origin [name]


Delete Remote version: $ git push origin:refs/tags/[name]


Merge the remote repository's tag to local: Git pull Origin--tags


Upload local tag to remote repository: $ Git push origin--tags


Create annotated tag:$ git tag-a [name]-M ' YourMessage '




4) Sub-module (submodule) Related Operations Command


Add sub-module: $ git submodule add [url] [path]


Example: $git submodule add Git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs



Initialize submodule: $ git submodule init----run only once when the warehouse is first checked out


Update submodule: git submodule update----need to run every time you update or switch branches



To delete a submodule: (4 steps away OH)


1) $ git RM--cached [path]


2) Edit the ". Gitmodules" file to delete the relevant configuration node of the Submodule


3) Edit the ". Git/config" file to delete the relevant configuration node of the Submodule


4) Manually delete the remaining sub-modules directory




5) Ignore some files, folders do not submit


Create a file with a name of ". Gitignore" under the repository root and write an unwanted folder name or file with one line per element, such as


Target


Bin


*.db




3, Git command detailed


Now that we have the local and remote repositories, let's try using Git's basic commands:


Git Pull: Updates the code locally from other repositories (both remote and local), for example: ' Git pull Origin master ' is updating the code for the Origin repository to the local master primary branches, This feature is similar to the SVN update


Git add: is to add the current changes or new files to the Git index, added to the Git index is recorded in the version history, this is a step before committing, such as ' git add app/model/user.rb ' will increase app/model/ USER.RB file into the git index, which is similar to the SVN add


git rm: Removes files from the current workspace and index, such as ' git rm app/model/user.rb ', which is similar to SVN's RM, Del


Git commit: Commit changes to the current workspace, similar to the SVN commit command, such as ' Git commit-m story #3, add user Model ', which must be submitted with-m to enter a commit message, This feature is similar to the SVN commit


Git push: Updates the local commit code to the remote repository, such as ' Git Push origin ', which updates the local code to the remote repository named Orgin


git log: View the history log, which is similar to the SVN log


git revert: Restore a version of the changes, you must provide a specific git version number, such as ' git revert bbaf6fb5060b4875b18ff9ff637ce118256d6f20 ', git version number is a generated hash


The commands above are almost all common to each version control tool, so let's try some of the git-unique commands:


Git branch: Adding, deleting, checking, and so on, for example ' git branch new_branch ' will create a new branch called New_branch from the current working version, ' Git branch-d new_branch ' will force the deletion called New _branch's branch, ' Git branch ' will list all the local branches


Git Checkout:git's checkout has two functions, one is to switch between different branch, such as ' Git checkout new_branch ' will switch to New_branch branch, and another function is to restore the function of the Code, For example ' git checkout app/model/user.rb ' will update the user.rb file from the last committed version, and all uncommitted content will be rolled back


Git rebase: Explained in the following two diagram will be more clear, after the rebase command executes, it is actually to move the branch from C to G, so that the branch has a function from C to G

Git Reset: The current working directory is completely rolled back to the specified version number, assuming that we have a-g five commit version, where C is the version number is BBAF6FB5060B4875B18FF9FF637CE118256D6F20, we executed the ' git reset Bbaf6fb5060b4875b18ff9ff637ce118256d6f20 ' Then there's only one a-c. Three submitted versions


Git stash: Put the current uncommitted work into the GIT work stack, when the time is ripe to apply back, here for the moment to mention the use of this command, the following in the tip of the key to explain


git config: This command allows you to add and change various git settings, such as ' git config branch.master.remote origin ' to set the remote repository of master to an alias called the Origin repository. This command will be used to personalize your git and create a unique git for you.


git tag: You can tag a specific version so you don't have to memorize a complex version number hash, for example you can use ' git tag revert_version Bbaf6fb5060b4875b18ff9ff637ce118256d6f20 ' to mark this version that you restored, then you can use the revert_version tag name instead of the hash value when you want to view the version later


This article is from the "Small Five Car God" blog, please be sure to keep this source http://linuxtech.blog.51cto.com/3670088/1772592

Introduction to Git and installation on CentOS

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.