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?
The “changes not staged for commit” message shows when you run the “git status” command and have a file that has been changed but has not yet been added to the staging area. This is not an error message, rather a notification that you have changed files that are not in the staging area or a commit.
If you just want to see the diff without committing, use git diff to see unstaged changes, git diff --cached to see changes staged for commit, or git diff HEAD to see both staged and unstaged changes in your working tree.
"Changes not staged for commit" means Some changes are not staged. So, to stage all changes perfectly, run this command: git add -A. Then, run this command: git commit -m "Update"
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:
git status
. You'll see "changes not staged".git add filename.cpp
git status
. You'll see "changes to be committed".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.
In CVS, SVN, BZR, and no doubt a dozen other tools, once a file is added that means it'll be included in the next commit.
Not so GIT.
In git you don't "add a file", you "add a change" (sometimes it's called "stage a change").
If you change a file twice you have to "add" it twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With