33

I'm trying to squash a few commits in a git repository.

> git rebase -i HEAD~3

Successfully rebased and updated refs/heads/staging.

A file opens titled git-rebase-todo :

pick a2f3467 Require statement incorrect
pick c41212e Require file in environment
pick 2743221 This should work

# Rebase c5f42f3..2743221 onto c5f42f3
# ..........

I tried changing the bottom two commits to squash from pick . I save the file, and I get the following error:

Unable to save ~/Documents/code/myapp/.git/rebase-emrge/git-rebase-todo

thumbtackthief
  • 6,093
  • 10
  • 41
  • 87
Brandon
  • 3,091
  • 2
  • 34
  • 64
  • 1
    It looks like a filesystem error rather than a Git one. What happens if you try to create a file in that location by hand? – Ben Mar 13 '13 at 12:17
  • What editor do you use? – poke Mar 13 '13 at 12:24
  • @poke I'm using SublimeText2 - nothing fancy (I don't think!) – Brandon Mar 13 '13 at 15:46
  • @Ben there is no `rebase-merge` folder in `.git` .... Is that normal? Something wrong with the way ST2 is loading up the commit? – Brandon Mar 13 '13 at 16:03
  • It doesn't normally exist, but should be created when needed during the rebase. Can you check whether the folder exists while the editor is open with the file `git-rebase-todo`? – Ben Mar 14 '13 at 10:03
  • Also, have you ever had a similar problem with other Git operations that involve editing? Do you use the same editor for commit messages? Can you try a different one? (Is there one that might give a more detailed error message, I wonder?) – Ben Mar 14 '13 at 10:05
  • @Ben I will check first thing tonight (at work right now). I don't use the editor very much when using git - i just scrape by on the command line. This is the first time I've really had a need for it. What would you recommend? Where do I change this setting? – Brandon Mar 14 '13 at 14:09
  • 1
    There isn't really a particular editor I would recommend. Just trying to narrow down the problem and wondering if it is the editor rather than the interactive rebase that is the problem. You can use `git config core.editor` to change the default editor. I think the first thing is to check while the editor is open whether the folder exists, and whether you can write files to it. – Ben Mar 14 '13 at 22:09
  • @Ben it is definitely SublimeText. The folder doesn't exist when I go to rebase, but the whole operation works fine if I do it in `nano`. Any thoughts? – Brandon Mar 15 '13 at 05:02
  • I've added a sublimetext2 tag to your question in case that attracts anyone who can help debug that. Otherwise, use `nano` for working with Git? – Ben Mar 15 '13 at 11:05
  • Thanks for your help @Ben! See Michael's response below - it worked for me – Brandon Mar 15 '13 at 15:04

3 Answers3

62

The problem is that when sublimetext2 is started, it doesn't block and immediately returns. Git then thinks that you're done editing the file and performs the rebase. That's why you see the

Successfully rebased and updated refs/heads/staging

message, before you even edited the file. Use the subl command instead, which is designed for such use. The github help tells you do configure it with

git config --global core.editor "subl -n -w"
Michael Wild
  • 24,977
  • 3
  • 43
  • 43
  • 1
    This stoped applying the rebase command immediately and made the file saveable again. Unfortunately it still doesn't continue after the save. – Andi Giga Dec 04 '15 at 08:55
  • Ok, I found the solution, you not only need to save the file, the editor also needs to be closed afterwards. Sry, did not know that, here is more info to the topic: http://stackoverflow.com/questions/22631863/setting-up-sublimetext-3-as-git-commit-text-editor – Andi Giga Dec 04 '15 at 09:27
1

In my experience the issue was due to user privileges.

If you're recieving Could not find the file "~/../../git-rebase-todo" error when saving the file, try running it as sudo:

sudo git rebase -i HEAD~3

However do keep in mind, this may change the owner of any files affected.

Alkarin
  • 464
  • 7
  • 20
0

I had similar issues using vs code, you can try in your terminal...

git config --global core.editor "code -n --wait"
yormen
  • 188
  • 2
  • 11