简体   繁体   English

Git-签出后所有文件都失去了可执行权限

[英]Git - All files have lost executable permission after checkout

I wanted to checkout an older commit to my working directory to mess around with something so I did the following command in the root of my repo: 我想签出对工作目录的较旧提交以弄乱某些内容,因此我在仓库的根目录中执行了以下命令:

git checkout 2aa2c5 .

But nothing happened, the # prompt simply came back. 但是什么也没发生,#提示只是回来了。 I did the command a few more times, but nothing seemed to happen. 我再执行了几次命令,但是似乎什么也没发生。 I then did: 然后我做了:

git status

Which showed that I was still on master . 表明我还在master I then did: 然后我做了:

git checkout master

As I wasn't sure what was happening and just wanted to get back to where I was. 因为我不确定发生了什么,所以只想回到原来的状态。 It came back with Already on master 回来了, Already on master

However now my website is not accessible, every single file now seems to have the permission 644? 但是现在我的网站无法访问,现在每个文件似乎都具有644权限? I am really not sure what has happened? 我真的不确定发生了什么事吗? It looks like although my original attempt to checkout a commit didn't do anything, it has messed with my file permissions, and/or file ownership. 看起来虽然我最初的尝试检出提交没有执行任何操作,但它却与我的文件权限和/或文件所有权混淆。

UPDATE: I don't think it is the permission that is the problem. 更新:我认为这不是权限问题。 I think the problem is that all the files have changed to root for the owner and group? 我认为问题在于所有者和组的所有文件都已更改为root? I was logged in as root when I did the checkout, will that have caused this? 我在结帐时以root用户身份登录,这会导致这种情况吗?

I am new to git and Linux file permission in general, if anyone could shed some light on this I would really appreciate it. 一般来说,我是git和Linux文件权限的新手,如果有人可以对此有所了解,我将非常感激。

Thanks 谢谢

Permissions and ownership are really critical for web servers. 权限和所有权对于Web服务器确实至关重要。 If you get this wrong, the wrong people (= crackers) can read or modify your files. 如果您弄错了,那么错误的人(=饼干)可以读取或修改您的文件。 So make sure you understand what you're doing. 因此,请确保您了解自己在做什么。

As a rule of thumb, never work as root . 根据经验,永远不要以root身份工作。 One silly mistake (like a flacky mouse that cut&pastes too much) can cost you the work of many hours. 一个愚蠢的错误(例如,过多地剪切和粘贴的笨拙的鼠标)可能会使您花费大量时间。

In your case, it seems that the ownership of the files was changed. 在您的情况下,似乎文件的所有权已更改。 To fix this, you will have to delete all the files (as root; be careful - if you make a mistake, a lot more that you might ever want will be gone!) 要解决此问题,您将必须删除所有文件(以root用户身份;请小心 -如果您犯了一个错误,那么您可能想要的更多东西将会消失!)

Try to keep the Git repo (ie delete everything except for the .git folder) but I fear that running git as root has already messed with some permissions in that folder as well. 尝试保留Git存储库(即删除.git文件夹以外的所有内容),但我担心以root身份运行git已经对该文件夹中的某些权限造成了困扰。

So your best bet might be to delete the whole tree (including the .git folder) and clone it again with the correct user. 因此,最好的选择是删除整个树(包括.git文件夹),然后使用正确的用户再次克隆它。

Related: 有关:

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

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