Git lists same file modified and not staged for commit?
git
Solution
It means that you made a change to `filename.cpp`, added that change (with `git add`), then made another change that has not yet been added.
The "changes to be committed" part means that Git has updated its index with a change. When you run `git commit`, the changes to the index will be used to create the new commit object.
The "changes not staged" part shows the difference between the index and your working copy.
You can reproduce what you're seeing like so:
- Edit filename.cpp
- Run `git status`. You'll see "changes not staged".
- Run `git add filename.cpp`
- Run `git status`. You'll see "changes to be committed".
- Edit filename.cpp again
- Run `git status`. You'll see both "changes not staged" and "changes to be committed".
Does that make sense? It's always a little tricky explaining how Git works.
Problem
For some reason Git is telling me I have a file which is both "to be committed" and also "not staged for commit"? This doesn't make sense: ``` % git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: Dir1/Dir2/filename.cpp # # 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: Dir1/Dir2/filename.cpp ``` `Dir1`, `Dir2` and `filename.cpp` are definitely all the same file. I had to add `filename.cpp` back again to get it to appear as a change to be committed (after it was originally in the repository). About the only thing that may have caused the problem was that I stashed, `pull --rebase`, then popped the `stash`? `.gitignore` does not list `Dir1`, `Dir2` or `filename.cpp` anywhere and the patterns don't suggest they would catch this file?