Santhosh
Santhosh

Reputation: 11774

git add not adding changes when used from inner directories

I have the following directories projectdir>subdir>subsubdir and .git folder inside projectdir

When i do git add . from subsubdir the changes inside projectdir are not added to Changes to be committed:

$ git status  
On branch master
Your branch is up to date with 'basicdjango/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   ../../.gitignore
    new file:   .env.example
    modified:   settings.py

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   ../../.gitignore

So how can i add changes till the projectdir

Upvotes: 2

Views: 45

Answers (1)

Romain Valeri
Romain Valeri

Reputation: 21928

. is syntax for "everything in the present directory" (and recursively inside its subdirectories).

So you could either :

  • move to the upper directory before doing your add. Let's just skip this option since avoiding this seemed to be the very source of your question.

  • do the same thing, but ease the process with an alias for your add, embedding a cd before it. I'm not too sure about recommending this one, though, as it could contribute to set lazy habits while being potentially dangerous.

  • refrain from using git add . every time. It's a handy tool but unneccessary in many cases with only a few files or directories. (And using only this shortcut could lead to just ignoring the existence of the index, which is probably not a good practice)

  • use git add -A which adds every file, with the same caveats stated above. (beware of old git versions where this had the same behaviour as git add .)

Upvotes: 2

Related Questions