Use of git version control tools
Preface
Previously, the project had been using svn for code version control. I was quite familiar with svn repository construction and svn usage, but git was a more powerful version control tool, in addition, many open-source experts on the Internet have hosted their own code on github, which is worth learning and using. Here we will record some of my experiences in using git, will be updated continuously
Getting started
My system is ubuntu12.04 desktop. By default, git is not installed in ubuntu, so you must first install it in the system.
Install [html] sudo apt-get install git-core in git
Apply for a git account
If you only need to copy the code you are interested in on github to your local computer and use it for modification without sharing the release, it doesn't matter if you don't apply for an account, you only need to clone the code locally by using git. However, this practice is not advocated by the Open Source spirit. It is the real geek to dare to show its own code and discuss and make progress together with others.
You can register an account at www.github.com to complete the application. The specific registration process is not detailed enough to upload the public key.
Git accesses the resource library through ssh, so you need to upload your public key to github.
On the github.com page, select Account settings in the upper-right corner, select SSH Keys, and add your own public key.
Manage your own projects
Create a git Repository
I personally develop a module and temporarily manage it using code tools (this allows you to back up and restore it in time). It is easy and convenient to create a git library. Just use the git inti command.
In this way, an empty local git repository is created and A. git subdirectory is created in the root directory of the repository. In the future, all file changes will be saved to this directory. There is a config file in the. git directory. You need to add your personal information before using it. Otherwise, we cannot add or modify any files.
Original config File
We need to add our own name and email address [html] git config user. name wangzhengyi
Git config user. email 15866883396@126.com after modification as follows
Git directory structure
Directory description [html] branches/the new version of Git no longer uses this directory, so it is generally empty
COMMIT_EDITMSG stores the comments of the last commit.
Configuration information of the config Project
Description Project description
HEAD project's current Branch Information
Hooks/Default "hooks" Script File
Index file. After git add, save the items to be added here.
Info/contains an exclude file, which specifies the file to be ignored in this project.
Logs/historical information of each refs
Objects/This directory is very important. It stores Git data objects, including commit, trees, blobs, and tagobjects)
Refs/identifies which commit (commit) git-add and git-rm each of your branches directs to add or delete files to or from the git library. In fact, it is wrong to use the git-add command to add files to the git repository, or at least not comprehensive. The essence of the git-add command is a package of the command "git-update-index -- add. Therefore, in addition to adding files, git-add can also identify file modifications. The commit operation can be performed only after git-add is called. The same is true for git-rm. It is a package of "git-update-index -- force-remove ".
Git-status
With this command, we can view the status of the version library. You can find out which files have changed and which files have not been added to the git library. We recommend that you use this command to check the database status before each commit operation. To avoid misoperation.
In fact, the most common mistake is to modify a file and directly call the commit operation without calling git-add through the git library, as a result, the file is not actually submitted. If the developer thinks that the file has been submitted and continues to modify or even delete the file, the modified content is not managed by version. If you check git-status before each submission, you can find this error.
Git-commit
Directly call the git-commit command and the comments are submitted. For each commit, git recommends a unique commit identification code for the Global Code. You can use the git-revert command to restore the code at any commit.
You can use git-diff to View File changes before submission.
Clone others' Projects
I believe that many of my friends, like me, started learning to use git just to get other people's open source project code. My original intention was to get and improve a php project code for converting Chinese characters to pinyin. The general method to get the code of a project is to use the git clone command to directly copy
For example, if you search for github using a Chinese character-to-pinyin code, you can see the following tips:
[Html] git clone ssh address
Example
Fork others' Projects
This is the most common use case for git beginners. We can also make a contribution when we see that Daniel shares his own code. First, you need to perform fork in the project you are interested in and fork out of your branch. After fork, you can see an ssh access address. Example: [html] git@github.com: wangzhengyi/HanziToPinyin. git copy code, use git clone command, at this time, the Code is generally the latest [html] git clone git@github.com: wangzhengyi/HanziToPinyin. git then, start to work hard, constantly modify and add content. Next, git add and git commit. Of course, you can use git checkout-B dev-branch to work in the Development branch. after the work is completed, confirm that there is no problem and merge it again: git merge
The modification is complete. It is very easy to publish your improvements. Direct git push origin master is submitted to your github project. The "Pull Requests" prompt is displayed on the page, allowing you to submit a merge Code request to the original project.
When you submit a "Pull Requests" request and the original project author accepts your request. Your modification records are included in the git log list, which proves your contribution. As a result, you have contributed to the open-source world.
After you register github, you will have a free space of 0.3G. However, you can only create public projects, which can meet the purpose of code sharing, in addition, its code display method is very elegant, based on the git Version Control System
Create a project on github
After logging on to github, you can find a button "New Repository" on the right side, click it, enter the project name, description, and URL, and then create a project, A prompt page is displayed. Record the Project address.