views:

86

answers:

5

Hello,

When I have:

  • dirty working directory,
  • dirty staging area,
  • and I copied some new files to the project,

how do I stage only the new ones?

git alias adduntracked=…
+1  A: 

I suggest something like this to copy:

for i in source/path ; do cp source/path/$i ./$i ; git add $i ; done

I'm not very well at shell scripting, but this would be an attempt

FUZxxl
+1 for the loop example
takeshin
A: 

git add -u is what I use to stage untracked.

Edit: comments below have reminded me that its git add . that adds untracked (along with changed files, which I think is not what you want?). I use the git add -u to stage deleted files.

Seba Illingworth
Help says that git add -u is actually --update.
Gauthier
From git help: -u, --update Only match <filepattern> against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.
takeshin
And precisely while I was pasting the text takeshin added, his reply appeared :)
Gauthier
A: 

git add untracked

halfdan
That's not actually a command, right? Do you mean `git add -i` then `4: add untracked`?
bstpierre
Correct. Sorry, should've pointed that out.
halfdan
+1  A: 

If you want to add all untracked files to the staging area:

git add .

I suppose that you want this, while keeping the unstaged changes to tracked files outside of the index.

git stash
git add . 
git stash apply

Would this help?

Gauthier
Thanks for this smart one :) What I was really looking for is: `for i in $(git ls-files -o) ; do git add $i ; done`
takeshin
@takesin: You don't really need the for-loop: `git add $(git ls-files -o --exclude-standard)`. Note that I added `--exclude-standard` so that you don't end up adding files that you want to ignore.
bstpierre
+3  A: 

This alias will respect your ignore patterns (builtin, global and per-directory, as described by the help for git-ls-files --exclude-standard. It will run at the top level of your tree.

[alias]
adduntracked=!git add $(git ls-files -o --exclude-standard)
bstpierre