Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 726
FractalSpace Avatar asked Nov 29 '12 16:11

FractalSpace


People also ask

How do I fix resolve changes not staged for commit?

Before you create a commit, you have to add the files you have changed to that commit. When you run the git status command before adding files to a commit, you'll see the changes not staged for commit message in the output of the command.

What is meant by changes not staged for commit?

"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"

How do I remove unstaged changes?

For all unstaged files in current working directory use: git restore . That together with git switch replaces the overloaded git checkout (see here), and thus removes the argument disambiguation. If a file has both staged and unstaged changes, only the unstaged changes shown in git diff are reverted.


2 Answers

git commit -a -m "message" 

The -a option will add all tracked files with modifications

like image 88
Goulart Avatar answered Nov 20 '22 04:11

Goulart


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.

like image 28
farmi Avatar answered Nov 20 '22 03:11

farmi