Explanation on git add

Source: Internet
Author: User

I. Preface
The GIT add command is mainly used to add information about the files to be submitted to the index library. When git commit is used, git submits files based on the content in the index library.
Ii. Basic
Git add <path> indicates add to index only files created or modified and not those deleted
I usually add our <path> to the index library in the form of git add <path>, which can be a file or a directory.
Git can not only identify the modified (excluding deleted) files in <path>, but also identify newly added files and add their information to the index library.
Iii. Git add-u
Git add-u indicates add to index only files modified or deleted and not those created
Git add-U [<path>]: add the modified or deleted file information in all tracked files in <path> to the index database. It does not process untracted files.
Omitted <path> indicates., that is, the current directory.
Iv. Git add-
Git add-A: [<path>] indicates to add information about modified or deleted files and untracted files in all tracked files in <path> to the index database.
Omitted <path> indicates., that is, the current directory.
5. Git add-I
You can run the GIT add-I [<path>] command to view all files modified or deleted but not submitted in <path>,
You can use the revert sub-command to view all untracted files in <path> and enter a sub-command system.
For example:
Git add-I
Staged unstaged path
1: + 0/-0 nothing branch/t.txt
2: + 0/-0 nothing branch/t2.txt
3: Unchanged + 1/-0 readme.txt

* ** Commands ***
1: [s] tatus 2: [U] pdate 3: [R] Evert 4: [a] dd untracked
5: [p] atch 6: [d] IFF 7: [Q] uit 8: [H] ELP
What now>
In this example, t.txtand t2.txt indicate that git add has been executed and is to be submitted. That is, it has been added to the index database.
Readme.txt indicates that it is already under tracked and modified, but it has not been executed git add. That is, it has not been added to the index database.
5.1. Revert subcommands
You can use the GIT add-I revert sub-Command (3: [R] Evert) to remove the files already added to the index library from the index library.
(3: [R] Evert) indicates to use 3 or R or revert and press enter to execute this command. After running this command, git will take the file list in the index library as an example.
Then, select a number. Enter "1" to indicate that git will generate 1st files in the file list of the index library.
"1-15" indicates that git will generate 1st to 15th files in the file list of the index library. Press enter to execute.
If we do not enter anything, press enter to end the revert sub-command and return the main command line of git add-I.
5.2 update sub-commands
You can use the update sub-Command (2: [U] pdate) to add tracked files to the index library. Its operation is similar to the revert sub-command.
5.3 add untracked sub-command
You can use the Add untracked sub-Command (4: [a] dd untracked) to add files not managed by git to the index library. Its operation is similar to the revert sub-command.
5.4 diff sub-commands
You can use the diff sub-Command (6: [d] IFF) to compare the differences between files in the index Library and the original version. Its operation is similar to the revert sub-command.
5.5. Status subcommands
The status sub-Command (1: [s] tatus) is similar to git add-I.
5.6 quit subcommands
The quit sub-Command (7: [Q] uit) is used to exit the GIT add-I command system.
Vi. Help
You can use the GIT add-H command to view the help document of the GIT add command.
Git add-H
Usage: git add [Options] [--] <filepattern>...

-N, -- dry-run dry run
-V, -- verbose be verbose

-I, -- Interactive interactive picking
-P, -- patch select hunks interactively
-E, -- edit current diff and apply
-F, -- force allow adding otherwise ignored files
-U, -- Update tracked files
-N, -- intent-to-add record only the fact that the path will be added later
-A, -- all add changes from all tracked and untracked files
-- Refresh don't add, only refresh the index
-- Ignore-errors just skip files which cannot be added because of errors
-- Ignore-missing check if-even missing-files are ignored in dry run

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.