2

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

1 Answer 1

2

. 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 .)

Sign up to request clarification or add additional context in comments.

6 Comments

So what should i use instead of git add .
i think git add -A is the solution. I tried it inside inner directories and it add changes of previous folder files
@SanthoshYedidi Yes, it's technically doing what you want. Just be cautious with it, it can be a source of mistakes.
why source of mistakes
git add -u will add every changes from tracked files, ignoring untracked. In any case, I'd highly recommend to rather use git add -p (long version is --patch) to be selective of what you add. I wrote some explanations on my website a while back about it: ghislain-rodrigues.fr/articles/git-add---interactive.html
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.