Changes not staged for commit even after git add [duplicate]
Asked Answered
T

2

5

Here are the git commands which I have typed

$ git add -u -n
add 'proj1/Foo.scala'
$ git add .
$ git add .
$ git commit -m "message"
On branch feature/branch
Your branch is up-to-date with 'origin/feature/branch'.
Changes not staged for commit:
    modified:   ../proj1/Foo.scala

So why did I get the Changes not staged for commit? as you can see that I did git add . twice

Now if I got ahead and do

git add ../proj1/Foo.scala

and then do commit it works. Why should I do each file specifically rather than just do git add .

Twinkle answered 29/3, 2016 at 17:33 Comment(4)
I usually do a git add * instead ... Only if you KNOW you want to add ALL the added/changed files in the current working directory .. But usually you know what you want to add to your commit. And -- You could shorten by committing and adding at the same time using git commit -a -m "message" which does the same thing as a git add *Hittel
git add . will only add files in the current directory (aka .). From the path in your copy/pasted commands, it looks like proj1 is up a directory?Peh
Why does it appear the file has changed location from one command to the next? When you dry-run the add, it shows the file location as proj1/Foo.scala, one directory below the current. Why then does the output later show the location as ../proj1/Foo.scala?Asphaltite
@Asphaltite It looks like they're in a subdirectory in the git repo. Since the first one used -u without a path, it looked at the whole repository, so it printed the path relative to the top of the repo. But commit shows paths relative to your current location.Peh
C
13

git add . by default will add files changed in current working directory and its subdirectories only.

If you want to add all files, use git add -A (this works in the latest versions of git).

Alternatively, as pointed by @Zak in comments, you can use git commit -am "commit message" to do this in a single step.

Chelton answered 29/3, 2016 at 17:40 Comment(2)
Or he could shorten it by using the "add" flag to the commit -- IE git commit -a -m "message"Hittel
git commit - a didnt work for me. but git add -A did the job.Doubleripper
K
4

I had a similar problem when git add <filename> did not work.
I cd down to the directory and did git add there and file was added as expected.

Kele answered 29/4, 2019 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.