FractalSpace
FractalSpace

Reputation: 5685

Can't get rid of "Changes not staged for commit'

I am unable to get rid of this state in which my repo is seem to be locked in. After a doing a reset to HEAD~1, I keep getting this notification about this single file being modified. 'add' and 'checkout' have not affect. I have core.autocrlf and core.safecrlf unset (empty).

Please see below:

$ git --version
git version 1.7.9.6 (Apple Git-31.1)

$ git status

# 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:   a_file_name.cpp

The followings commands (ran individually) have no affect:

$ git checkout -- a_file_name.cpp
$ git reset a_file_name.cpp
$ git add a_file_name.cpp
$ git reset --hard
$ git clean -n
<nothing>
$ git clean -f
<nothing>

$ git status

# 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:   a_file_name.cpp

and it goes on ...

What did I do wrong?

Response to @Don's suggestion below (git rm), no change, but here is how it goes:

$ git rm 
error: 'a_file_name.cpp' has local modifications
(use --cached to keep the file, or -f to force removal)
$ git rm -f a_file_name.cpp
rm 'a_file_name.cpp'
$ git status

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    a_file_name.cpp
#
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    a_file_name.cpp
#

$ git commit -m"tmp"
[master 2a9e054] tmp
1 file changed, 174 deletions(-)
delete mode 100644 a_file_name.cpp

$ git status
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    a_file_name.cpp
#

Pretty much back to sq.1

Upvotes: 26

Views: 24853

Answers (5)

Sonic Soul
Sonic Soul

Reputation: 24989

this could happen if the file in question has a different capitalization.

in my case it was

README.md readme.md

git won't let you simple git add ... a case change.

you can fix that by doing something like

git mv -f readme.md README.md

Upvotes: 1

farmi
farmi

Reputation: 343

A round about way that worked for me, is to:

  1. recreate the file that I deleted.

  2. git add path/filename

  3. git rm --cached path/filename

  4. delete the file

  5. git add .

  6. git commit --amend # if not on an already pushed branch.

Upvotes: 6

Goulart
Goulart

Reputation: 99

git commit -a -m "message"

The -a option will add all tracked files with modifications

Upvotes: 7

Code-Apprentice
Code-Apprentice

Reputation: 83587

Be sure that you are in the same directory as the file when you run any git commands. Alternatively, you can use a relative or absolute path for files used with git commands. The output from git status should indicate the subdirectory where the file is located. I find it strange that the output you posted here doesn't show that.

Upvotes: 2

jeremy
jeremy

Reputation: 4314

Do you need any of the changes in the modified file? git-reset by default leaves the files in the directory tree.

git reset --hard

will reset and write over the files in your working tree with the files in the commit.

Have you done a git diff after each of the steps to see if any changes actually exist?

Upvotes: 2

Related Questions