Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git says I have unstaged changes but I do not show them

I am executing this command on the second file I want to remove (the first was JetBrains' .idea folder files which are now in .gitignore), but I am not able to:

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch gf5/console/basic.php' --prune-empty --tag-name-filter cat -- --all
Cannot rewrite branches: You have unstaged changes.

So how do I know what "unstaged" files git is referring to when it does not list them, and how do I fix this?

PS the issue is not stash(es), I do not have any and have not done any stashing on this repo ever.

NOTE: I did a git status and receive this:

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   gf5/console/basic.php

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)

//(and a whole long list of files)
like image 658
Oliver Williams Avatar asked Jan 09 '17 18:01

Oliver Williams


1 Answers

AHA!! I figured out what is going on. Read the last few sentences for a little insight.

The answer was to first do:

git status

This showed modified files in RED, which I presume means they are somehow "deleted" in git's mind. I then did:

git add --all

From there I committed all the staged files using SourceTree (sorry I didn't stay with the command line all the way). I went ahead and simultaneously pushed changes up to the server but that would be optional.

The above command then worked successfully.

When I tried to run the above command on a different file, I had the same problem. So I again ran git status and it turns out that the file that I just removed from history is still there and so you need to do this:

git rm /previous_file_you_just_removed_from_history.php

Also to clarify, the filter-branch command will remove the history of that file from all commits, but it will NOT remove the changes that you made to that file. I.e. that removed file is still the sum of all changes you made to it up to that point. I hope this helps clear this concept up for someone else.

like image 83
Oliver Williams Avatar answered Sep 21 '22 04:09

Oliver Williams