git add details (always remember when to use the add parameter, embarrassing)

Source: Internet
Author: User
Tags diff
First, preface
The git add command is primarily used to add information about the files we want to submit to the index library. When we use git commit, Git commits the file based on the contents of the index library.
Second, the basic
Git add <path> represents 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>,<path> can be a file or a directory.
Git can not only determine the <path>, modify (excluding deleted) files, but also can determine the new files, and add their information to the index library.
Third, Git add-u
Git add-u means add to index only files modified or deleted and not those created
git add-u [<path>]: Adds information about the modified or deleted files in all tracked files in <path> to the index library. It does not process untracted files.
Ellipsis <path> representation., that is, the current directory.
Four, Git add-a
git add-a: [<path>] means to add file information from all tracked files in <path> to the index library that have been modified or deleted and all untracted.
Ellipsis <path> representation., that is, the current directory.
Five, Git add-i
We can use Git add-i [<path>] command to view <path> in all modified or deleted files but not submitted files,
and through its revert subcommand can view all the untracted files in <path>, and enter a sub-command system.
Like what:
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>
The T.txt and t2.txt here indicate that git add has been executed and is ready to be submitted. That is already added to the index library.
Readme.txt indicates that it is already under tracked, it has been modified, but has not been executed by git Add. That is not yet added to the index library.
5.1, revert sub-command
You can remove files that have been added to the index library from the index library by using the REVERT subcommand (3: [R]evert) of the Git add-i.
(3: [R]evert) indicates that the command is executed by 3 or R or revert plus a carriage return. After executing the command, GIT will sample the list of files in the index library.
Then select by number. Entering "1" means that Git will sample the 1th file in the list of files in the index library.
"1-15" means that git will sample the 1th file in the list of files in the index library to the 15th file. The carriage return will be performed.
If we do not enter anything, the direct carriage return will end the REVERT subcommand and return to the main command line of Git add-i.
5.2. Update sub-command
You can add an already tracked file to the index library by using the UPDATE subcommand (2: [u]pdate). Its operation is similar to the REVERT subcommand.
5.3, add untracked sub-command
With the Add untracked subcommand (4: [A]dd untracked) You can add files that are not yet managed by Git to the index library. Its operation is similar to the REVERT subcommand.
5.4. diff subcommand
The DIFF subcommand (6: [D]iff) allows you to compare the differences between the files in the index library and the original version. Its operation is similar to the REVERT subcommand.
5.5. Status Sub-command
The STATUS subcommand (1: [s]tatus) function is similar to git add-i
5.6, the Quit sub-command
The QUIT subcommand (7: [Q]uit) is used to exit the git add-i command system
Vi. Help
We can use the git add-h command to see the help documentation for 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 edit current diff and apply
-F,--force allow adding otherwise ignored files
-U,--update update tracked files
-N,--intent-to-add record only the fact, the path would 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 is 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.