简体   繁体   English

Git rebase -i不在终端中/仅适用于sudo

[英]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. 我只是想在当前分支中使用git rebase -i HEAD~2编辑一些提交。 I use Ubuntu 10.10 and had to install gvim first to make the command work. 我使用Ubuntu 10.10,必须先安装gvim才能使命令起作用。 Afterwards, the command opens a gvim window with the normal rebase content. 之后,该命令将打开一个包含常规rebase内容的gvim窗口。 But when I want to save the file gvim says 但是当我想保存文件时,gvim说

".git/rebase-merge/git-rebase-todo" E212 “ .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. ). rebase命令也将在启动后立即完成(带有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. 当使用sudo执行相同的命令时,rebase可以正常工作,但之后会发生文件由root拥有并且我不再具有写权限的情况。

  • On my ArchLinux system gvim is opened directly in the terminal where I run git rebase -i and everything works. 在我的ArchLinux系统上,我直接在运行git rebase -i的终端中打开gvim,一切正常。

  • I tried different terminals (Gnome terminal, LXTerminal, XTerm) - always the same problem 我尝试了不同的终端(Gnome终端,LXTerminal,XTerm)-始终存在相同的问题

What is the problem here and how to solve it? 这里有什么问题以及如何解决? It should work without sudo. 它应该在没有sudo的情况下工作。

Edit 1 编辑1

  • Some files in .git/... are owned by root and are read-only. .git/...中的某些文件由root拥有,并且是只读的。 All directories and files in the first level of .git/ are owned by me. 第一个.git/级别中的所有目录和文件都归我所有。 With ls -l --recursive .git/ | grep root 使用ls -l --recursive .git/ | grep root 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... ls -l --recursive .git/ | grep root我试图检测是哪些文件,但是输出没有给出文件的路径...
  • Should all files in .git/ belong to the user? .git/所有文件都应该属于该用户吗? May this be the reason for the problem? 这可能是问题的原因吗?

EDIT 2 编辑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. 即使使用sudo chown -R user:user .git/chmod u+w -R .git/更改了.git中所有文件的所有权和写权限给用户,( ls -l现在也显示了sth。就像-rw-r--r-- 1 user user )问题仍然相同。

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. 首先,我认为这是因为我的存储库位于ntfs驱动器上,因此文件权限无法正常工作。 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. -f选项启动vim很有帮助 (我读过其他人也以同样的方式解决它),但是我不知道为什么。

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 更改文件夹中的权限并不能消除问题。在我的情况下,这是因为umask设置为27,默认情况下,该文件会使用

-rw-r----- -rw-r -----

permissions, Obviously git tires to create a directory which can't be saved by the user. 权限,显然git tires创建了一个用户不能保存的目录。 This is therefore a bug in git. 因此,这是git中的错误。

Note: I noticed that using the editor vim gets around this bug. 注意:我注意到使用vim编辑器可以解决此错误。 It seems that gedit and kate have problems with the permissions. 看来gedit和kate的权限有问题。

I'm using spf13 conf and I solved the issue with following steps: 我正在使用spf13 conf,并通过以下步骤解决了该问题:

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. 看来您的某些变基过程已被破坏,删除这些目录可以恢复它。

Do a sudo chown -R user .git to giver user back ownership of the files. 进行sudo chown -R user .git授予user对文件的所有权。 You shouldn't ever need to run git with sudo , as doing so can result in problems like this. 您永远不需要使用sudo运行git ,因为这样做可能会导致类似这样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM