West Project management tool git one Piece

Source: Internet
Author: User
Tags git workflow perforce how to use git version control system


Objective
The word Git believes that everyone is not unfamiliar with the development of children's shoes are inseparable from it every day. Of course, assuming that your project is not functional and distributed, you probably never used Git, or you may not have heard of it. Just, that's not the point, the point is this article, and we'll talk about Git together. Learn about Git from a macro perspective.



Point Order
Before writing this article, I have been thinking about how to position it? Is it a basic tutorial to use, or a macro introduction to the Git mechanism? Because the recent time is very tight, there is not so much free time, so. Reasoning decided to write a macro on the introduction, as for the basic tutorial, online has been very much, I have looked at, write better than me, so I do not need to fraught again.
In view of this, my position is that the main content of this article is on the macro to talk about the changes that Git brings us. and Git's internal implementation, or mechanism. Finally, share your experience with Git in your project.

Version number control
What is version number control? Why should I care about it? I think the question I'm asking is a little silly. There have been development of children's shoes This is needless to say, if you really do not know, then go to Baidu a bit.

So. Do you know how many version number control systems there are? Have you ever thought about why Git is used in the company instead of SVN? Or does it use SVN instead of Git? Let's look at the difference between them.

    • Local version number control system
Remember what we did when we backed up files and backed up data very early on? Anyway, my approach is to copy the entire file (directory). Copy to a hard drive, or a network disk. Then name them yourself. This is a purely manual job. As we all know, the chance of error will be greatly added if the labor is repeated manually. However. In order to solve the problem, people have developed many kinds of local version number control system for a long time, most of them adopt some kind of simple database to record the changes of the files.


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvagfwchlszwu2njg4/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "align=" Middle "style=" Background-color:inherit ">
One of the most popular is called RCS (Revision Control System). It is still visible on many computer systems today. The RCS command can be used even after the developer Toolkit is installed on a popular MAC OS X system. It works basically to save and manage file patches. A file patch is a text file in a specific format. The change of content before and after the revision of the corresponding document is recorded. So. Depending on the patch after each revision. RCS is able to calculate the file contents of each version number by constantly patching.

    • Centralized version number control system
The advent of RCS has greatly facilitated the control and maintenance of historical documents (data). Soon after, however, another problem arose. Operating system differences, resulting in the inability of developers to work together, especially in version number control.

The clever Human found a solution, that's all. Centralized version number control system (centralized. Referred to as CVCS) came into being.
Like this kind of system. such as CVS. Subversion, and Perforce. There is a single, centrally managed server that keeps the revision numbers of all the files, and the people who work together are connected to the server through the client, taking out the latest files or submitting updates.

Over the years, this has become a standard practice for version number control systems. And in the enterprise development, centralized version number control system is also the most common and most popular.



This approach brings many advantages, especially compared to the old-fashioned local VCS. Today, everyone can see to some extent what other people in the project are doing. Administrators can easily control the permissions of each developer, and managing a CVCS is far easier than maintaining a local database on each client.


The ancients had an old saying. Called "The Curse of the blessing." The Curse of the Blessed. "

He's saying. No matter what things have two sides, there is no absolute good and bad. is just a relative comparison.

What we want to pursue is a balance, or, for us, the benefits outweigh the disadvantages. Seems to be a little off-topic ah ... Back to the chase. As you can see, the most obvious disadvantage of a centralized version control system is the single point of failure of central server. Suppose the outage is an hour, then within this hour. No one will be able to submit updates and will not be able to work together.


If there is a problem with the central server disk, it happens that you did not make a backup, or the backup is not timely. There is a risk of data loss. The worst case scenario is a complete loss of the entire history of the project. Some snapshot data saved locally by the client is the hope of recovering the data. But this is still a problem, you cannot guarantee that all the data have been fully extracted beforehand.

There is a similar problem with the local version number control system, where the entire history of the project is saved in a single location, and there is a risk of losing all historical update records.

    • Distributed version number control system
Why is it that humans are always the smartest? Human beings are always able to solve the problems they encounter. This time is no exception.

Based on the above questions. The Distributed version control system (distributed, DVCS) was unveiled. In such systems, such as Git,mercurial,bazaar and Darcs, the client does not only extract file snapshots of the latest version numbers. Instead, the code repository is completely mirrored. So. No matter what the problem is with a server that works together, you can recover from a local repository regardless of the image. Because of the fetch operation every time. is actually a full backup of the code warehouse at one time.

Further. Many of these systems are able to specify and interact with several different remote code warehouses.

This allows you to collaborate with people from different working groups on the same project. You can set up different collaborative processes based on your needs. For example, a hierarchical model of workflow, which is not possible in the once centralized system.

Thought
So, simply put, what exactly is Git like in a system? Let's take a look at the ideas he mapped out.

    • Direct recording of snapshots, rather than differences
The main difference between git and other version-number control systems is that git only cares about whether the overall file data is changing, while most other systems only care about the detailed differences in the file content.

This type of system (cvs,subversion. Perforce,bazaar, and so on) each time you record which files were updated and what rows were updated.


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvagfwchlszwu2njg4/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "style=" Background-color:inherit ">
Git does not store the variance data that changes before and after.

In fact, Git is more like taking a snapshot of a changed file and recording it in a tiny file system. Each time the update is submitted. It will take a glance through the fingerprint information of all the files and make a snapshot of the file, and then save an index that points to the snapshot. To improve performance. If the file does not change. Git does not save again. Instead, just link to the last saved snapshot.

    • Nearly all operations are run locally
The vast majority of operations in Git simply require access to local files and resources without a network connection.

But assuming that with CVCS, almost the same all operations need to connect to the network. Because Git keeps a history update of all current projects on the local disk. So the processing speed is very fast.
For example, if you want to browse through the project's History update summary, Git does not have to go to the outside server to fetch the data back, but reads it directly from the local database. So whenever you can read it right away, you don't have to wait. Given the difference between a file that wants to look at the current version number and the version number one months ago, Git takes a one-month snapshot and the current file for a differencing operation instead of asking the remote server to do it, or pulling the old version of the file locally to make the comparison.
With CVCS, you won't be able to do whatever it is without the Internet or disconnecting the VPN. But with Git, even if you're on a plane or a train. are happy to submit updates frequently and then upload them to the remote repository when there is a network.

Same, on the way home, you can continue to work without a VPN connection.

    • Maintain data integrity at all times
Before you save to Git, all data is evaluated for content checksum (checksum). This result is used as a unique identifier and index for the data.

Other words. It's impossible for Git to know nothing after you've changed the file or folder. This feature, as a design philosophy of Git, is built at the bottom of the overall architecture. So if the file becomes incomplete when it is transferred, or if the disk is damaged causing the file data to be missing, Git can immediately detect it. Git calculates the checksum of the data using the SHA-1 algorithm, and calculates a SHA-1 hash value by the structure of the file's contents or folder. As a fingerprint string.

The string consists of 40 hexadecimal characters (0-9 and a-f).
Git's work relies entirely on this type of fingerprint string, so you'll often see this hash value. As a matter of fact. Everything stored in a Git database is indexed with this hash value. Rather than by file name.

    • Most operations only include data
Most of the Git operations you use often add data to the database. Any irreversible operation, such as deleting data, can make it difficult to rewind or reproduce the historical version number. In other VCS, if the update has not yet been submitted, it is possible to lose or confuse the content of the changes, but in Git, once the snapshot is submitted, you do not have to worry about losing data, especially in the habit of pushing to other warehouses regularly.
    • Three status of files
For no matter what a file. There are only three states within Git: committed (committed). Changed (modified) and staged (staged). Submitted indicates that the file has been safely saved in the local database. The change indicates that a file has been altered, but has not yet been committed, and that a staged representation puts the changed file on the list to be saved on the next commit.
This is when we see Git managing the project. Three working areas for file flow: Git's working folder, staging area, and local repository.




The main Git workflow is as follows:

    1. Change some files in the working folder.

    2. Take a snapshot of the modified file. Then save to the staging area.

    3. Submit the update. File snapshots saved in the staging area are permanently dumped into the Git folder.

So. We can infer the state from the location of the file: Suppose it is a specific version number file saved in the Git folder. is in the committed state, and if it is changed and placed in the staging area, it is staged, assuming that it has been changed since the last time it was taken, but has not yet been placed in the staging area. is the changed state.



Feel
Because Git was developed under Linux. It is mainly used as the distributed version number control system under the open source system Linux.

Just because of the transplant of some great gods makes it possible for users under Windows to use it.

Just, for compatibility. The emulation of Git in the Windows environment is still slightly off. But that doesn't mean that the functionality of Git is missing under Windows.

Just under Windows. Easier to make some unpredictable problems. Of course, these problems can still be solved, is a bit of trouble.


For example, permissions for files under Windows cannot be fully consistent with Linux, so file permissions checked out with Git may appear to be changed.

In addition, because of the new line in Windows and Linux is not the same, collaborative development also easy problems. So the students who use Git on Windows need to add the following 2 lines of configuration parameters:
git config--global core.filemode falsegit config--global core.autocrlf truethe first sentence ignores the modification of file permissions. The second sentence is to checkout the file when you take the initiative to turn LF into Crlf,check in when you take the initiative to turn CRLF into LF
Of course, consider developing on the Windows platform. The Tortoisegit client of the graphical interface is recommended, and the Git plugin is also available under the Java IDE. For example, under Eclipse, you can install Git by installing plugins. In IntelliJ idea, the plugin is installed by default, just tick activate in the settings and configure it.
As for how to use Git, there is no more to say, there are a lot of tutorials on the Internet.

A post is recommended here. Talking about how to use Git under Eclipse. Article address. Speaking is quite specific, there is a need to see for themselves.

Conclusion
This article focuses on some of the things that Git has on the macro and the fundamentals of Git.

We are committed to having a major understanding of Git. Of course. This is based on the use of the version number control system.

And there's no need to dwell on the question of whether to use SVN or Git. Personally think. Suppose it is to learn, then it is best to understand it all. Assuming the company has requirements, then according to the company's requirements. Not required two models are used. Depending on the details of the company. Assuming that you intend to evolve to the architect in the future, you need to think more about the advantages and disadvantages of various technologies and tools, and you have to be clear on your chest, and that's the main thing.

References :

    1. http://git-scm.com/
    2. http://www.devtang.com/blog/2012/02/03/talk-about-svn-and-git/

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

West Project management tool git one Piece

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.