Git tutorials-Managing changes

Source: Internet
Author: User
Tags version control system

Now, suppose you have mastered the concept of staging area completely. What we're going to talk about here is why Git is better designed than other version control systems because git tracks and manages changes, not files.

You will ask, what is the modification? For example, you add a row, this is a change, delete a row, is also a modification, change some characters, is also a modification, delete some and add some, is also a modification, even create a new file, also counted as a modification.

Why is git managing changes, not files? We still do the experiment. The first step is to make a change to Readme.txt, such as adding a line of content:

is a distributed version control system.Git is free software distributed under the GPL.Git has a mutable index called stage.Git tracks changes.

Then, add:

$ git add readme.txt$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: readme.txt#

Then, modify the Readme.txt:

is a distributed version control system.Git is free software distributed under the GPL.Git has a mutable index called stage.Git tracks changes of files.

Submit:

commit -m "git tracks changes"[master d4f25b6] git tracks changes 1 file changed, 1 insertion(+)

After submitting, look at the status:

$ git status# On branch master# Changes not staged for commit:#   (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: readme.txt#no changes added to commit (use "git add" and/or "git commit -a")

Gee, how did the second Amendment not be submitted?

Don't get excited, let's review the operation process:

First modification, git add second modification,git commit

You see, as we said earlier, Git manages the modifications, and when you use the git add command, the first modification in the workspace is put into staging area, ready to be submitted, but the second modification in the workspace is not put into staging area, so it is git commit only responsible for submitting the staging area changes, That is, the first modification is submitted, and the second change is not committed.

Once submitted, use git diff HEAD -- readme.txt the command to see the difference between the latest version of the workspace and the repository:

76d770f..a9c5755 100644--- a/readme.txt+++ b/readme.txt@@ -1,4 +1,4 @@ Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage.-Git tracks changes.+Git tracks changes of files.

As can be seen, the second modification is indeed not committed.

Then how to submit a second Amendment? You can continue git add git commit , or you can not worry about the first modification, the git add second modification, and then git commit , the equivalent of two changes after the merger of a piece submitted:

First modification, git add Second Amendment, git addgit commit

OK, now, submit the second change and start the summary.

Summary

Now you understand how git keeps track of changes, every time you change it, and if you don't add get to staging area, you won't join commit in.

Git tutorials-Managing changes

Related Article

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.