1

I would like to have git add -p allow me to review not only the changes in the modified files, but in the untracked files.

I have found this question but unlike in that case, I do not want to stage all untracked files. I want to be given the option to stage or to not stage the addition of some of the untracked files.

I tried to do git add -p -A but this only went through all the changes in the modified files, and quit, without showing me the new untracked files.

Community
  • 1
  • 1
Daniel Gray
  • 1,697
  • 1
  • 21
  • 41

1 Answers1

1

You can't—but the change in the untracked file, if you git add it, is that the entire file is new, so if you could, you'd just get one giant diff hunk, saying "this file is all-new".

Just view the untracked file and decide whether to git add it. If it should never be added, consider telling Git to shut up about it by listing it in an ignore file. (But note that listing a file after it's added is too late: Git is already tracking it and no longer looks for an entry in a "shut up about these files" file.)

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks for the information! It's just that there were several untracked files I wanted to add, and not some others (that aren't ready/finished yet) and I couldn't just do a blanket `git add ./path/to/stuff/` because some of the files inside weren't ready yet either. I have found that `git add -i` allows me to add untracked files in an easier way (without having to write out the whole path) but it was a big buggy (it just hanged and wouldn't quit), so I'll just have to add the files by hand it seems :) I don't mind doing it but it would be nice to have a way to do this faster! – Daniel Gray Mar 24 '17 at 08:37
  • 1
    Yeah, I've never quite gotten the hang of `git add -i`. I find it easier to run `git status` or `git status --short`, save the output to a temp file if needed, and turn the temp file into appropriate `git add`s and gitignore entries. – torek Mar 24 '17 at 12:16