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

git rebase vs merge
git rebase stackoverflow
git rebase squash
git rebase origin/master
git rebase conflict
git rebase commit
git rebase master into feature branch
git rebase interactive tutorial

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?

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.

Rebasing, differs from merge by rewriting the commit history in order to produce a straight, linear succession of commits. Rebase is one of two Git utilities that specializes in integrating changes from one branch onto another. The other change integration utility is git merge. Merge is always a forward moving change record. Alternatively, rebase has powerful history rewriting features.

Try closing any programs that have the folder open, such as editors, explorer windows, command prompts, and FTP programs. This always fixes the issue for me on Windows.

What is a "rebase" in Git?, Rebase is one of two Git utilities that specializes in integrating changes from one branch onto another. The other change integration utility is git merge . Merge is  If <upstream> is not specified, the upstream configured in branch.<name>.remote and branch.<name>.merge options will be used (see git-config for details) and the --fork-point option is assumed. If you are currently not on any branch or if the current branch does not have a configured upstream, the rebase will abort.

Just close your IDE (VISUAL STUDIO/ATOM etc). It might work

An introduction to Git merge and rebase: what they are, and how to , Compare git rebase with the related git merge command and identify all of the potential opportunities to incorporate rebasing into the typical Git workflow. git rebase in depth One of Git's core value-adds is the ability to edit history. record, in git we can change history to suit our needs. This gives us a lot of powerful tools and allows us to curate a good commit history

When I see this on my machine, it's worse than just a "some process has the file open". The actual ownership of the file gets jacked up to the point where I (running as administrator) can only access it after rebooting.

Nearest I can tell, IIS is part of the problem. If I switch between two major branches that require a lot of files to modify, git will delete a file or directory (usually DLLs) while IIS is trying to do something or another with it. At this point, the IIS process automatically overwrites the file on disk with a version that's locked and appears to be owned by nobody.

Stopping IIS at this point doesn't do it. Best I've found out to do is to reboot, and remember to stop IIS before changing across major branches in the future.

I know that doesn't really answer the question, but might be helpful to others.

git rebase, Understand the differences between MERGE and REBASE and learn you can use these Duration: 16:12 Posted: Sep 6, 2018 The git fetchcommand downloads commits, files, and refs from a remote repository into the local repository. It updates your remote-tracking branches. The git fetchcommand allows you to see the progress of the central history, not forcing you to merge the changes into your repository. It does not affect your local work process.

On Windows, it can be a TortoiseGIT process that blocks those files. Open task manager and end process TGitCache.exe.

Merging vs. Rebasing, Meet git rebase -i, the perfect way to rewrite history and make everyone think that you produce perfect code the first time! What does git rebase do  The Git command above will rebase the current branch onto [base], which can be any kind of commit reference (an ID, a branch name, a tag, or a relative reference to HEAD). When ran, Git performs the following steps: Identifies each commit that is an ancestor of the current commit but not of [base].

Git MERGE vs REBASE, Desktop GUI or Command Line? To make learning Git as easy as possible for you, we provide this book in two different versions: This version teaches Git on the  git rebase -i HEAD~10 (10 will be the number of your last commits in a row) This is a tricky command because it won’t work if there are other commits in between, so only use it when you see all

The life-changing magic of git rebase -i, In Git, the rebase command integrates changes from one branch into another. It is an alternative to the better known "merge" command. Most visibly, rebase differs​  Rebasing In Git, there are two main ways to integrate changes from one branch into another: the merge and the rebase. In this section you’ll learn what rebasing is, how to do it, why it’s a pretty amazing tool, and in what cases you won’t want to use it.

Rebase as an Alternative to Merge, Rebase is another way to integrate changes from one branch to another. Rebase compresses all the changes into a single “patch.” Then it  The git rebasecommand has a reputation for being magical Git voodoo that beginners should stay away from, but it can actually make life much easier for a development team when used with care.