Git rebase -i not in terminal / only works with sudo

I just want to edit some commits with git rebase -i HEAD~2 inside the current branch. I am using Ubuntu 10.10 and I had to install gvim first for the command to work. After that, the command opens the gvim window with the normal forwarding contents. But when I want to save the file, gvim says

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

[Unable to open file for writing]

The rebase command also ends immediately after starting (using Successfully rebased and updated refs/heads/master. ).

  • When executing the same command with sudo rebase works, but then it happens that the files are owned by root, and I no longer have write permissions.

  • On my ArchLinux system, gvim opens directly in the terminal, where I run git rebase -i , and everything works.

  • I tried different terminals (terminal Gnome, LXTerminal, XTerm) - always the same problem

What is the problem and how to solve it? It should work without sudo.

Change 1

  • Some files in .git/... owned by root and are read-only. All directories and files on the first level .git/ belong to me. Using ls -l --recursive .git/ | grep root ls -l --recursive .git/ | grep root I tried to determine what files are, but the output does not give the paths to the files ...
  • Should all files in .git/ belong to the user? Could this be the cause of the problem?

EDIT 2

  • Even after changing permissions and writing all files inside .git to a 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 remains the same.
+6
source share
4 answers

My solution was:

Run

 $ git config --global core.editor "gvim -f" 

Firstly, I thought this was because my repository was on the ntfs drive, so file permissions would not work correctly. But even after installing the drive with the correct file permissions, the problem remains the same. Running vim with the -f option helps (I read about other people solving it the same way), but I don't know why.

+15
source

Grant sudo chown -R user .git for user back file ownership. You will not need to run git with sudo , as this can lead to such problems.

0
source

I have the same problem. changing permissions in the folder does not fix the problem In my case, this is because umask is installed 27, which by default creates files with

-rw-p -----

permissions, Obviously, git buses create a directory that cannot be saved by the user. Therefore this is a bug in git.

Note. I noticed that using the vim editor turns around this error. Gedit and kate seem to have permission issues.

0
source

I am using spf13 conf and I solved the problem with the following steps:

 rm -rf ~/.vimswap rm -rf ~/.vimviews rm -rf ~/.vimbackup 

It seems that some kind of forwarding process has been broken, and you can restore these dirs.

0
source

Source: https://habr.com/ru/post/911188/


All Articles