The use of git add command in Linux is detailed

Source: Internet
Author: User
Tags commit svn

When I first started to learn git, I never understood why to have git add this command, feel git submitted to trouble
I need


git add xxx.md
git commit-m "Add xxx"
Git push Origin Master
To submit a file to the far end, I miss the SVN I have been using, think of an SVN commit is all done, git why so troublesome?

It's been used a lot longer, I discovered the benefits of git, saying why git works better than SVN, and my understanding is probably because git has decoupled all the changes, submissions, collaborations, and mergers into a process that makes it very rare to have errors and a very high maintainability of the project version.
Of course, a lot of places I still understand is not very deep, I now only say why have git add this command.

The essence of git add is to maintain the list of files you want to submit next time.

For example:
For example, you are developing a function, the file has changed a lot, but have not submitted, and no git add, this time the boss let you urgently add a function, in order to achieve this function, you modify a a,b,c three files, you can put these three files git add in, So the three documents are in the next list of documents to be submitted, as soon as the submission, you found that there is a C file does not need to be modified, you can git reset c, remove C from the list, this time git commit will only submit a,b files, you will not worry about submitting those previously modified files.

The key to git add is adding modifications to the manifest rather than adding the file to the list
For example:

If a file has been a.txt under version control, the content is

Hello World
And then you add another line.

Hello World
Hello
You can then execute git add a.txt, and the next git commit change will be submitted, but if you haven't had time to git commit, you've added a line

Hello World
Hello
Hello Beijing
If you do not git add a.txt again, this modification is not to be submitted

Git add operation experiment

$ CD manual56/
--View the status of Git's current version library
$ git status
# on Branch Master
Nothing to commit (working directory clean)

--Enter the chapter directory I want to modify
$ CD docs/chapter_17/
$ vim 17.5.0.0.0.md-Create a new MD file that simply writes "Only a Test" string, Wq save exit Edit state.

--View status
$ git status
# on Branch Master
# untracked Files:
# (use "Git add <file> ..." to include in what'll be committed)
#
# 17.5.0.0.0.MD--A new file with a red color is not submitted yet, and the file name in this line is red.
Added to commit but untracked files present add file add with "Git add" to track


Git add 17.5.0.0.0.md adds a single file, multiple files can be separated by spaces, such as git add 17.5.0.0.0.md 17.5.0.0.1.md 17.5.0.0.2.md, or you can use Git add-a to add all the files.

--Execute Add command
$ git Add 17.5.0.0.0.md

--View individual file version status
$ git status 17.5.0.0.0.md
# on Branch Master
# Changes to be committed:
# (use ' git reset head <file> ... "to Unstage)
#
# New FILE:17.5.0.0.0.MD
#

--View the entire library version status
$ git status
# on Branch Master
# Changes to be committed:
# (use ' git reset head <file> ... "to Unstage)
#
# New FILE:17.5.0.0.0.MD
#


Manually open the C:\Documents and settings\skyman\manual56\docs\chapter_17\17.5.0.0.0.md with Markdownpad, enter the Chinese string inside, and save the exit. Then look at the version library status, the display of the green color has been cached, the red color is modified but not cached.

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.