Git Getting Started: easy to understand

Source: Internet
Author: User

Tag: git

The most popular version control software: git ================================ git is already one of the most popular version control software. Programmers all over the world are using it. It comes from Linus and is now used for kernel version control. On GitHub, the most popular code hosting software, you can find code for almost all open-source projects. Forum Control Software: Do I need it? ----------------------- It is true that for many people-especially non-programmers, they may not think of software with dedicated version control. However, many people actually have similar requirements for version control. For example, Tom is a member of the Community's secretariat. What they often need to do is to write activity documents, then we can change it to something that everyone thinks is okay. If you are not lucky, Tom may have a folder called "opensuse event planning", which contains such a pile of Files "opensuse event planning", "activity planning 1 ", "Activity Planning 2", "activity planning 3", "Activity Planning 4 "... "event planning 20" (poor Tom, a document has been changed no less than 20 times) is very effective because we may find that there is a problem with the planning of the 5th versions, we are going to try again in version 3rd. However, we can also see that this method is ugly: We have 20 backups for a file, and pay attention to the file name. If you can do this, there is only one "opensuse event plan" in the folder, but when I need 5th versions, I will make one "and restore it to 5th versions! ", Then we open this file, and it is in version 5th. Similarly, we can retrieve any version. This is version control. This happens too much in the program, so various version control software emerged. In fact, some projects have grown to more than 1,000th or even higher versions ...... Single-line workflow ------------ we can think of a project as a warehouse, and then we can stuff our stuff into the warehouse or take out what we want. Git is the repository administrator. The following is an example. I hope to have an intuitive impression and do not want to fully understand and grasp it. '''Bashmkdir myproject // assume that myproject is the working directory CD myproject git init // git <-(init), and notify the repository administrator, initialize echo 'eat the banana '> file // edit a file git add file // Add the file to the repository git commit-m'add first file' // submit the change echo' in the current directory' eat the apply '> file // modified the file git add file // Add the file to the repository git commit-M 'Update first file' // submit the change '''. At this time, we have two commit, let's take a look at the work log: '''bashgit log # The following is the output # commit ac1371173b4e630ddaebda3f9f5d948b36146c07 # auth Or: Norman Mo <[email protected]> # Date: Thu Jun 27 21:59:10 2013 + 0800 # update first file # commit 3c43cc913454f92bb4b80c56ba45e4ffaf556fc0 # Author: norman Mo <[email protected]> # Date: Thu Jun 27 21:58:48 2013 + 0800 # add first file '''. We have submitted it twice. Let's take a look at what is in the current file: '''bashcat file # obviously, the output is 'eat the application' # Now, let's get back the first version of the file git checkout 3c43cc913454f92bb4b80c56ba45e4ffaf556fc0 -- filecat file # at this time, Eat banana uses the '''method most common for a single user to write a little code, submit it to the repository. Write a bit and submit it to the repository. Then, when there is a problem, it will be rolled back. Git is very powerful. Basically everything you think of can be done. The data submitted to the repository is basically not lost, and the code is controlled like a time machine. Multi-person collaboration -------- git is very powerful, and the above is just a function. Considering that Tom's secretariat has two people who write at the same time. Among them, Tom wrote the first six chapters and his companions wrote 7th ~ Chapter 12. At this time, you can consider using this method: to set up a public warehouse. Tom maintains his own version, and his companions maintain his own version. Then we merge the code to the public warehouse on a regular basis, and then fetch the new version and merge it before submitting it to the public warehouse. If they use plain text, some text analysis methods can be achieved without being proofread. '''Git commit-m' finish ch5' // assume that Tom has finished chapter 1 git push // Tom pushes the code to the remote repository ''' git commit- m'finish ch11' // assume that Tom's companion completes Chapter 1 git pull // pull will pull down the latest version, merge, and then push it to the remote warehouse '''. To avoid confusion, a new branch is opened to develop new features and merge the branches. Automatic Code publishing --------- another powerful function is to automatically release code. As a matter of fact, this is used in many clouds. Specifically, when the server receives a push using git's hooks, the server can automatically run some scripts. You can also use hooks on the client. when the client is preparing to push, the client runs some scripts first. For example, we want to kill all 'P' processes after each server receives a push, and then re-restart the 'p' process. We can modify 'hooks/post-receive ': '''echo "killing all P process... "killall-9 Pecho" restart p process... "p''' more ...... --------------- This tutorial is now available. Try it now! Installation Method in opensuse: '''sudo zypper in git ''' should be installed by default. In general, the help for Linux commands is '-- help' option: '''git -- help'''. In addition, a sub-command also has help: '''git init -- help''' here is an interactive tutorial on simulating git running in a browser. If you are interested, try it: 

Git Getting Started: easy to understand

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.