git4--Management Changes

Source: Internet
Author: User

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 do you say Git Are you 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:

$ cat readme.txt
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.

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 Readme.txt :

$ cat readme.txt 
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 of files.

Submit:

$ git Commit"git tracks changes"
[Master D4f25b6] git tracks changes
11  insertion (+)

After submitting, look at the status:

git status
# on Branch Master
# changes not staged for commit:
# (use "git add <file> ..." To update what would 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 time modification - git add - Second Modification -git commit

you see, we talked about it earlier, Git Management is modified when you use git add after the 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, git commit only responsible for the staging area changes submitted, that is, the first modification was submitted, the second modification will not be submitted.

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

$ git diff HEAD -- readme.txt 
diff --git a/readme.txt b/readme.txt
index  the d770f..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.

So how do you commit a second change? You can continue git add and then git commit or don't worry about submitting the first change, first git add second modification, and then git commit

First time modification - git add - Second Modification - git add -git commit

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

Summary

now, you understand. Git is how to track changes every time you modify, if not add to staging area, that's not going to join commit the.

git4--Management Changes

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.