Git Learning Note one

Source: Internet
Author: User
Tags using git version control system

Introduction to 1.git distributed and centralized

Centralized version control system The biggest problem is the need to network to work, if it is OK in the LAN, the bandwidth is big enough, fast enough, but if on the Internet, if you encounter a slow speed, you may submit a 10M file will take 5 minutes, it is not to suppress the death of people.

What is the difference between a distributed version control system and a centralized version control system? First of all, the distributed version control system does not have a "central server", everyone's computer is a complete repository, so that when you work, you do not need to network, because the repository is on your own computer. Since everyone has a full repository on their computers, how can multiple people collaborate? For example, you change the file a on your computer, your colleague also changed the file a on his computer, when you two just push their changes to each other, you can see each other's changes. Compared with centralized version control system, the security of Distributed version control system is much higher, because everyone's computer has a complete version of the library, a person's computer is broken do not matter, casually from other people to copy one. Centralized version control system central server if there is a problem, everyone can not work.

In the actual use of Distributed version control system, in fact, rarely in the two people on the computer to push the revision of the Repository, because maybe you two are not in a local area network, both computers can not access each other, or your colleague is sick today, his computer did not boot. Therefore, the distributed version control system usually also has a "central server" computer, but the role of this server is only to facilitate "exchange" everyone's changes, without it everyone also work, just exchange changes inconvenient.

Installation of 2.git

After you install git properly, you can $git--version to see if the GIT version number is installed successfully

  

Set up the last step after the installation is complete

  $ git config --global user.name "Your Name"   $ git config --global user.email "[email protected]"
  因为Git是分布式版本控制系统,所以,每个机器都必须自报家门:你的名字和Email地址。你也许会担心,如果有人故意冒充别人怎么办?
  这个不必担心,首先我们相信大家都是善良无知的群众,其次,真的有冒充的也是有办法可查的。
小技巧
 $ git clear 清除一下当前的界面
 
查看你设置的 用户名和邮箱
 $ git config user.name
 $ git config user.email

Go back to the top level directory CD .

LS can see all the file folders under the current directory in the previous text after

3. Create our first Repository

A) find a suitable place to create an empty directory

The PWD command is used to display the current directory (under window to make sure that the language cannot appear otherwise it will appear hehe problem)

B) use git init to turn this directory into a repository git can manage.

Instantly Git has built the warehouse, and tell you is an empty warehouse (empty Git repository), careful readers can find the current directory is a directory of more than one, .git this directory is git to track the management of the repository, it's OK don't manually modify the directory inside the file , or change the mess, the Git repository to destroy. (If you don't see the. git directory can be seen directly using the Ls-ah command)

Now we write a first.txt file (which must be placed in the Git repository)

The first step is to use git add to tell git to add files to the repository:

$ git Add readme.txt

Second step git commit tells Git to commit the file to the repository

$ git commit-m "inside is the description of this submission can be entered in any Content"

Commit can submit many files at once you can add different files multiple times.

  

Next, if we want to modify the First.txt file. After you change it, you can view the results in git status.

  

 The above command tells us that First.txt has been modified but is not ready to commit the changes. If we do not clearly modified the Readme.txt use git diff This command to view the changes.

As the git diff name implies is to view difference, the format is the UNIX common diff format, you can see from the command output above, we added a "distributed" word in the first line. After knowing what changes have been made to Readme.txt, it is much more reassuring to submit it to the warehouse.   then commit the changes and submit the new file is the same two steps, the first step is git add : there is no output. Before performing the second step git commit , let's run through git status the status of the current warehouse:

Git status tells us that we are going to be submitted including first.txt. Finally in view. Remember to always check the status of Git status.

If you want to view your own or someone else's submitted logs when you are working in a team, you can see what I'm doing by using git log--author= "Shiyao" directly.

4. Version fallback

Like this, you continue to modify the file, and then constantly submit changes to the repository, like playing RPG, every pass through the game will automatically save the state, if there is no past, you can also choose to read the status of the previous level. In some cases, you can manually save the boss before hitting it, so that if the boss fails, you may start again from the nearest place. Git, too, can "save a snapshot" whenever you feel that the file has been modified to a certain level, a snapshot that is called in Git commit . Once you've changed the file, or deleted it by mistake, you can recover from the latest one commit , and then continue working instead of losing all of your work for months.

The $ git log name shows the most recent commit log we can see for all commits. If you have too much idle stuff, you can add--petty=oneline parameters

How do you go back to the previous version?

A) First let git know which version of the current version is in git with head to indicate the current version of the previous version is the head^ version is head^^ if 100 write 100 ^ write not come so written head~100

$ git reset--hard head^

View content inside using $ cat first.txt;

At this point we can use the Git log to see the repository's status.

You can also go back to the previous version without closing the command line.

Git's version fallback is very fast because git has a pointer to the current version inside, and HEAD when you roll back the version, git just points the head fromappend GPL

  

Git Learning Note one

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.