Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git add only all new files, not modified files [duplicate]

Tags:

git

git-add

Is there a way to only add new files and not add modified files with git? That is, files that are listed as untracked with git status.

Other than ofcourse adding each file separately.

It's not absolutely necessary to do this in my case, the real question for me is answered here: How to make git-diff and git log ignore new and deleted files?

That is, don't show diff on new files, so I'm asking this more because i couldn't find an answer to it anywhere.

like image 704
Andreas Fliesberg Avatar asked Apr 02 '13 10:04

Andreas Fliesberg


People also ask

How do you git add all modified files but not untracked?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.

Does git add only add modified files?

It does not add any new files, it only stages changes to already tracked files. git add -A is a handy shortcut for doing both of those.

Does git add * Add untracked files?

So, if you run git add . within a sub directory, it won't add changes to files outside that sub directory. Second, git add . adds both tracked and untracked files.

How do I exclude files from git add?

Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.


1 Answers

Maybe

git add $(git ls-files -o --exclude-standard)

git ls-files lets you list the files managed by git, filtered by some options. -o in this case filters it to only show "others (i.e. untracked files)"

The $(...) statement passes the return value of that command as an argument to git add.

like image 171
Nils Werner Avatar answered Sep 19 '22 19:09

Nils Werner