1git-add(1) 2========== 3 4NAME 5---- 6git-add - Add file contents to the changeset to be committed next 7 8SYNOPSIS 9-------- 10'git-add' [-n] [-v] [-f] [--interactive | -i] [--] <file>... 11 12DESCRIPTION 13----------- 14All the changed file contents to be committed together in a single set 15of changes must be "added" with the 'add' command before using the 16'commit' command. This is not only for adding new files. Even modified 17files must be added to the set of changes about to be committed. 18 19This command can be performed multiple times before a commit. The added 20content corresponds to the state of specified file(s) at the time the 21'add' command is used. This means the 'commit' command will not consider 22subsequent changes to already added content if it is not added again before 23the commit. 24 25The 'git status' command can be used to obtain a summary of what is included 26for the next commit. 27 28This command can be used to add ignored files with `-f` (force) 29option, but they have to be 30explicitly and exactly specified from the command line. File globbing 31and recursive behaviour do not add ignored files. 32 33Please see gitlink:git-commit[1] for alternative ways to add content to a 34commit. 35 36 37OPTIONS 38------- 39<file>...:: 40 Files to add content from. Fileglobs (e.g. `*.c`) can 41 be given to add all matching files. Also a 42 leading directory name (e.g. `dir` to add `dir/file1` 43 and `dir/file2`) can be given to add all files in the 44 directory, recursively. 45 46-n:: 47 Don't actually add the file(s), just show if they exist. 48 49-v:: 50 Be verbose. 51 52-f:: 53 Allow adding otherwise ignored files. 54 55-i, \--interactive:: 56 Add modified contents in the working tree interactively to 57 the index. 58 59\--:: 60 This option can be used to separate command-line options from 61 the list of files, (useful when filenames might be mistaken 62 for command-line options). 63 64 65Configuration 66------------- 67 68The optional configuration variable 'core.excludesfile' indicates a path to a 69file containing patterns of file names to exclude from git-add, similar to 70$GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to 71those in info/exclude. See link:repository-layout.html[repository layout]. 72 73 74EXAMPLES 75-------- 76git-add Documentation/\\*.txt:: 77 78 Adds content from all `\*.txt` files under `Documentation` 79 directory and its subdirectories. 80+ 81Note that the asterisk `\*` is quoted from the shell in this 82example; this lets the command to include the files from 83subdirectories of `Documentation/` directory. 84 85git-add git-*.sh:: 86 87 Considers adding content from all git-*.sh scripts. 88 Because this example lets shell expand the asterisk 89 (i.e. you are listing the files explicitly), it does not 90 consider `subdir/git-foo.sh`. 91 92Interactive mode 93---------------- 94When the command enters the interactive mode, it shows the 95output of the 'status' subcommand, and then goes into its 96interactive command loop. 97 98The command loop shows the list of subcommands available, and 99gives a prompt "What now> ". In general, when the prompt ends 100with a single '>', you can pick only one of the choices given 101and type return, like this: 102 103------------ 104 *** Commands *** 105 1: status 2: update 3: revert 4: add untracked 106 5: patch 6: diff 7: quit 8: help 107 What now> 1 108------------ 109 110You also could say "s" or "sta" or "status" above as long as the 111choice is unique. 112 113The main command loop has 6 subcommands (plus help and quit). 114 115status:: 116 117 This shows the change between HEAD and index (i.e. what will be 118 committed if you say "git commit"), and between index and 119 working tree files (i.e. what you could stage further before 120 "git commit" using "git-add") for each path. A sample output 121 looks like this: 122+ 123------------ 124 staged unstaged path 125 1: binary nothing foo.png 126 2: +403/-35 +1/-1 git-add--interactive.perl 127------------ 128+ 129It shows that foo.png has differences from HEAD (but that is 130binary so line count cannot be shown) and there is no 131difference between indexed copy and the working tree 132version (if the working tree version were also different, 133'binary' would have been shown in place of 'nothing'). The 134other file, git-add--interactive.perl, has 403 lines added 135and 35 lines deleted if you commit what is in the index, but 136working tree file has further modifications (one addition and 137one deletion). 138 139update:: 140 141 This shows the status information and gives prompt 142 "Update>>". When the prompt ends with double '>>', you can 143 make more than one selection, concatenated with whitespace or 144 comma. Also you can say ranges. E.g. "2-5 7,9" to choose 145 2,3,4,5,7,9 from the list. You can say '*' to choose 146 everything. 147+ 148What you chose are then highlighted with '*', 149like this: 150+ 151------------ 152 staged unstaged path 153 1: binary nothing foo.png 154* 2: +403/-35 +1/-1 git-add--interactive.perl 155------------ 156+ 157To remove selection, prefix the input with `-` 158like this: 159+ 160------------ 161Update>> -2 162------------ 163+ 164After making the selection, answer with an empty line to stage the 165contents of working tree files for selected paths in the index. 166 167revert:: 168 169 This has a very similar UI to 'update', and the staged 170 information for selected paths are reverted to that of the 171 HEAD version. Reverting new paths makes them untracked. 172 173add untracked:: 174 175 This has a very similar UI to 'update' and 176 'revert', and lets you add untracked paths to the index. 177 178patch:: 179 180 This lets you choose one path out of 'status' like selection. 181 After choosing the path, it presents diff between the index 182 and the working tree file and asks you if you want to stage 183 the change of each hunk. You can say: 184 185 y - add the change from that hunk to index 186 n - do not add the change from that hunk to index 187 a - add the change from that hunk and all the rest to index 188 d - do not the change from that hunk nor any of the rest to index 189 j - do not decide on this hunk now, and view the next 190 undecided hunk 191 J - do not decide on this hunk now, and view the next hunk 192 k - do not decide on this hunk now, and view the previous 193 undecided hunk 194 K - do not decide on this hunk now, and view the previous hunk 195+ 196After deciding the fate for all hunks, if there is any hunk 197that was chosen, the index is updated with the selected hunks. 198 199diff:: 200 201 This lets you review what will be committed (i.e. between 202 HEAD and index). 203 204 205See Also 206-------- 207gitlink:git-status[1] 208gitlink:git-rm[1] 209gitlink:git-mv[1] 210gitlink:git-commit[1] 211gitlink:git-update-index[1] 212 213Author 214------ 215Written by Linus Torvalds <torvalds@osdl.org> 216 217Documentation 218-------------- 219Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. 220 221GIT 222--- 223Part of the gitlink:git[7] suite 224