From February 12, 2014 to work until now, has been nearly half a year, but also remember the first contact with the centralized version of the control tool SVN surprise, this has been independently developed for me, just understand that the original code can also be managed like this! Of course, now the understanding of SVN, but also know the operating principle, to meet the work of some simple code version control. For git this version of the control tool, in fact has been heard for a long time, but also understand the difference between git and svn working principle, but also want to get started contact, but the download of some textbooks too thick, too much content, has not been practiced. Exactly, these days relatively well-off, and then find the relevant information, began to slowly contact with the use of git, and students hope to get started together Ah!
Less gossip, let's get started together!
1. Download and install Git
I'm using the installation package for this URL http://www.cr173.com/down.asp?id=30724
You can also download Git's Chinese install package from other websites.
Because Git installation is relatively simple, so I just focus on the point, no mention of the interface, keep the default.
Below this interface, is chooses our git software installs the location, everybody follows own custom to be possible.
The following page is to choose which components to install, leave the default
Choose what version to install, we install GIT bash version can
This interface is selected by default
The installation was successful.
We open the Git Bash in the Start menu, and if this is the interface, our git is already installed successfully.
2. Build a git repository
Git is a distributed version Control tool, and SVN is a centralized version control tool. The point is that if you use SVN for versioning, then we first need a server, as the SVN version of the server, when we commit the operation, SVN is to synchronize our local code to the SVN server, that is to say, There are all our updated versions of the code on the SVN server, but only the latest version is saved on the computer where we write the code locally, so if our SVN server hangs up, the previous version record may be at risk of being lost.
And Git is a distributed strategy, that is, git not only on the server to save our various versions of the records, in each git computer's local disk, also save the version of the record file, so we can implement offline version submission, when we can network, We can submit the local repository to our git server. So git works differently with SVN, and the other differences between the two tools can be seen in this article http://blog.csdn.net/yihui8/article/details/6445847
Below, we begin to introduce Git's simple use, although some Linux commands are needed, but don't be afraid, it's easy.
First, we need to create a few folders to mimic our usage environment. Because I have only one computer, my computer is a git server and a git user. So, we create the following document structure to mimic our usage environment.
Develop: is the folder where we need to store the code, in this case, we have written a code file that needs to be versioned
Git: This is the installation folder for our Git software, so it's easy to put it here.
Repository: English is the meaning of the warehouse. This folder is intended to mimic the folder on the server side where the version files are stored.
After creating these folders, we first need to create an empty version control library in the server's folder.
Open our Git Bash and enter the following command
So, just below our directory, we created an empty repository named Share.git.
Once we have created the repository, we can see the following file structure, which indicates that our repository was created successfully
After creating the repository, open the Develop folder and create two folders User1,user2, we use these two folders to imitate two users who use Git.
First, go into the User1, right click, choose Git Bash so that we open the User1 folder in the directory of the Command line window
Then we enter Git clone/e/repository/share.git/
In this way, we have copied the repository on the server to the local, we can see a share folder under our User1 folder, this is our copy of the repository, we can put the code we need to manage under the Share directory, version control
Below, we mimic the version control of the code, using the Echo statement to write "Hello Git" in the Index.txt file
Then use the Cat command to see if the text was written successfully
Once the write is successful, we can include this file in our repository, but before we join the repository, we need to create a user to commit to the server repository.
Follow the command below to create the user
After creating the user, execute the git add index.txt command, first add the Index.txt to our version control, then execute the git commit index.txt and commit the changes to our local repository.
After this is done, the following interface appears, which is the text editor of the Vim to write our submitted version of the comments
Vim is often used under Linux editor, after this interface, click I, enter into the insert mode, after writing the comments, click ESC to exit the insert mode, back to the command mode, enter: Wq, save the changes and exit, so that our files are submitted to the local repository.
Note that we use the commit command just to submit our files to our local repository, the repository on the server, and we do not have our information, so we also need to submit our files to the server repository, so what should we do?
Enter GIT push Origin master
With the push command, we submitted our repository to the Master branch on the server, and origin represents the address of our server repository.
After the commit succeeds, other users can pull down the server's repository and collaborate on the development.
Git super Simple Introductory Tutorial--write to a classmate who has never dared to use git