git rebase -i HEAD~<n> does not show the commit list or the commands in vi

Issue

I am trying to squash come commits but the guides I find on the internet (e.g.this from Git) do not work for me:

> git checkout master
> git checkout -b masterBAK
> git log --oneline --graph --decorate -n 4
*   047687e (HEAD) Merged PR 100: Fix pytest using marker
|\  
| * 8ca0695 (origin/correct_bug) add something to pytest
| * 7b247c8 mock some function
|/  
*   5c5c75a (tag: v1.4.0) Merged PR 090: cleanup imports

> git rebase -i HEAD~3

I am now expecting to see a list of commits followed by a list of commands as in the link above. Instead I see a blank page in vi, i.e. a cursor where I can write using vim commands followed by tilde symbols. I can quit with ":q". What can I do to see the commits and squash them as described in the guide above?

I don’t think it matters, but I use meld in some settings:

> git config -l
diff.tool=meld
merge.tool=meld
difftool.prompt=false
..
core.editor=/usr/bin/vi -w   [Solution: faulty -w flag]

Solution

core.editor=/usr/bin/vi -w

This is the wrong setting. In particular the -w option here is evil.

If your vi is one of the more traditional versions, -w tells the editor that the next argument is the window size. This is expected to be a number, and if it’s not a number, odd things may happen. Git will pass a file name here, which generally won’t be a number. The effect will be to ignore the file name, and open a temporary file.

If your vi is a vim variant, the -w flag means that the next argument is a script output file. Again, this consumes the file name that Git wants vim to open, so that vim opens an empty temporary file instead. Worse, vim now appends stuff that you type into the rebase instruction sheet.

Whatever told you to put -w here is wrong. Remove the -w.

Answered By – torek

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published