Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

".git/rebase-merge/git-rebase-todo" E212

[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.

Edit 1

  • 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?

EDIT 2

  • 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.
like image 587
user905686 Avatar asked Mar 20 '12 11:03

user905686


1 Answers

My solution was:

Run

$ 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.

like image 97
user905686 Avatar answered Oct 13 '22 20:10

user905686