50

Git won't let me rebase from anywhere.

Cannot rebase: Your index contains uncommitted changes.
Please commit or stash them.

Following the instructions from this answer:

$ git update-index -q --ignore-submodules --refresh
$ git diff-files --ignore-submodules

Both do not produce any output but that one does:

$ git diff-index --cached --ignore-submodules HEAD --
:100644 000000 cab819f1e5ed6cc7cff374eecae273e1d6ae6a01     0000000000000000000000000000000000000000 D  .idea/codeStyleSettings.xml
:100644 000000 2953f353d2c65dd62e36926accb7f645a600b7e0 0000000000000000000000000000000000000000 D  .idea/dictionaries/roxy.xml
:100644 000000 0e7ecef362d8a77067edf4bae5972f33185bd986 0000000000000000000000000000000000000000 D  .idea/inspectionProfiles/Project_Default.xml
:100644 000000 3b312839bf2e939fea3ebdef15630a4b33e57caf  0000000000000000000000000000000000000000 D    .idea/inspectionProfiles/profiles_settings.xml
:100644 000000 e31af55b33d82e28f471a2ba51b63c2a91fa53b7 0000000000000000000000000000000000000000 D  .idea/php.xml
:100644 000000 9c25e8d4f1169b5d3103b14fdb60e7d7c3975b70 0000000000000000000000000000000000000000 D  db/sfront.sql

and I can't delete those files:

$ git rm --cached .idea/php.xml
fatal: pathspec '.idea/php.xml' did not match any files

Any ideas that can help me?

EDIT: git stash

Fixed my problem. I'm not sure I understand what happened though. The files that it complain about were supposed to be ignored.

2240
  • 1,547
  • 2
  • 12
  • 30
Pixy
  • 1,048
  • 4
  • 18
  • 27
  • Files cannot both be ignored *and* be part of your repository. If `git` detected changes in those files, then they had previously been added to the repository (which means that even if they were listed in `.gitignore` they wouldn't be ignored -- you told `git` they were important, after all). – larsks Jan 26 '14 at 02:36
  • Makes sense. Some of the files were added after I noticed them. That's fine but why couldn't they be deleted with git rm? And what did git stash do to fix that? Just curious, I'd like to understand what happened. – Pixy Jan 26 '14 at 02:41

2 Answers2

81

git stash stores the different files away from everything else, returning your working directory to the last commit. Once you have done your rebase, run git stash pop. This will return those files to the working directory and allow you to work as before.

EDIT: A good link for learning all about the git stash command: Git Tools - Stashing and Cleaning

jamesthollowell
  • 1,550
  • 15
  • 21
  • 2
    Thanks for the clarification. I have one more question then, when I tried to commit git said it didn't find any changes. Why did commit not see any changes but stash did? – Pixy Jan 26 '14 at 02:51
  • Did you do `git stash pop` afterwards? – jamesthollowell Jan 26 '14 at 03:33
  • 1
    No I don't need those files. All the files in .idea are from my IDE and an old backup of my db. If they remain in the stash can it cause me problems in the future? – Pixy Jan 26 '14 at 04:28
  • Probably. I think basically it will mean you can't use `git stash` anymore. If you didn't pop the stash, that would be why git can't see any changes. – jamesthollowell Jan 26 '14 at 04:43
  • It couldn't see the changes before I did git stash. Is there any way I can clear the stash? I don't care about those files. – Pixy Jan 26 '14 at 04:53
12

Probably not yet for a golden shovel, nevertheless I always use --autostash option when rebasing with uncommitted changes, thus:

git rebase --interactive SHA_WHERE_REBASE_ONTO^ --autostash

Mike
  • 1,225
  • 10
  • 21