Git rebase -i not in terminal / only works with sudo
I simply want to edit some commits with git rebase -i HEAD~2 inside the current branch. I use Ubuntu 10.10 and had to install gvim first to make the command work. Afterwards, the command opens a gvim window with the normal rebase content. But when I want to save the file gvim says
[Cannot open file to write]
Also the rebase command finishes right after starting (with Successfully rebased and updated refs/heads/master.).
When doing the same command with sudo the rebase works, but afterwards it occurs that files are owned by root and I have no write permissions anymore.
On my ArchLinux system gvim is opened directly in the terminal where I run git rebase -i and everything works.
- I tried different terminals (Gnome terminal, LXTerminal, XTerm) - always the same problem
What is the problem here and how to solve it? It should work without sudo.
- Some files in .git/... are owned by root and are read-only. All directories and files in the first level of .git/ are owned by me. With ls -l --recursive .git/ | grep root I tried to detect which files that are but the output does not give the paths of the files...
- Should all files in .git/ belong to the user? May this be the reason for the problem?
- Even after changing ownership and write permissions of all files inside .git to user with sudo chown -R user:user .git/ and chmod u+w -R .git/ (ls -l now shows sth. like -rw-r--r-- 1 user user) the problem stays the same.
My solution was:
$ git config --global core.editor "gvim -f"
First, I thought it was because my repository was on an ntfs drive so the file permissions wouldn´t work correctly. But even after mounting the drive with correct file permissions the problem stayed the same. Starting vim with the -f option helps (I read about other people solving it the same way), but I don´t know why.
Do a sudo chown -R user .git to giver user back ownership of the files. You shouldn't ever need to run git with sudo, as doing so can result in problems like this.
I have this same problem. changing the permissions in the folder does not eliminate the problem In my case it is because the umask is set 27 which by default creates files with
permissions, Obviously git tires to create a directory which can't be saved by the user. This is therefore a bug in git.
Note: I noticed that using the editor vim gets around this bug. It seems that gedit and kate have problems with the permissions.
I'm using spf13 conf and I solved the issue with following steps:
rm -rf ~/.vimswap rm -rf ~/.vimviews rm -rf ~/.vimbackup
It seems that your some rebase process had been broken and remove these dirs can recover it.