Kyralessa Kyralessa - 10 months ago 93
Git Question

git rebase: "error: cannot stat 'file': Permission denied"

I'm using git, and made a small commit followed by a large one. I decided to use

git rebase
to squash the two commits together before pushing them. (I've never done this before.)

So I did:

git rebase -i HEAD~2

This gave me my editor, where I chose to pick the earlier commit and squash the later one. When I saved, git said:

error: cannot stat 'filename': Permission denied

Could not apply sha1 for later commit... initial line of text for that commit


  • Neither commit appears when I do
    git log

  • git status
    tells me I'm "Not currently on any branch."

  • One file is listed as modified and in the index, and two files are listed as untracked. My first commit had just one file (I think), and my second commit had a good dozen.

What happened!? How do I fix it?

Answer Source

I've only ever seen this error on Windows and what it seems to mean is that something blocked git from modifying a file at the moment when it tried to a apply a patch.

Windows tends to give processes exclusive access to files when it shouldn't really be necessary, in the past virus checkers have been one source of suspicion but I've never proved this conclusively.

Probably the easiest thing to do is to abort and try again, hoping that it doesn't happen the next time.

git rebase --abort

You can attempt to use git apply and knowledge of what commit git was actually trying to do before doing a git rebase --continue but in all honesty I wouldn't recommend this. Most of the times I've seen this tried there's been a better than evens chance that something gets accidentally missed or messed up.