如何在Git中处理多个Linux用户文件

发布于 2025-01-02 23:43:38 字数 830 浏览 1 评论 0原文

我有一个 Git 项目,它有点特殊,因为树中的文件是由两个不同的用户生成的。示例:

# ls -la

drwxr-xr-x 13 ivan ivan  4096 2012-02-02 16:52 .
drwxrwxrwx 32 root root  4096 2012-01-28 21:37 ..
drwxr-xr-x  2 ivan ivan  4096 2012-02-07 20:41 system
drwxr-xr-x  2 ivan ivan  4096 2012-02-07 20:41 compatibility
drwxr-xr-x 33 ivan ivan  4096 2011-12-08 18:13 resources
drwxr-xr-x  8 ivan ivan  4096 2012-02-07 20:41 .git
-rw-r--r--  1 ivan ivan   307 2012-02-02 16:52 .gitignore
-rw-r--r--  1 bulk bulk   700 2011-11-01 20:10 base.log
.....

Git 仅由一个用户 (ivan) 控制,但守护进程会生成分配给批量用户的文件。当守护进程添加新文件时,一切都很好,但是当守护进程更改文件时,git 停止工作并说:

error: unable to unlink old 'base.log' (Permission denied)

我知道最好的选择是让守护进程以 ivan 用户身份运行,但这在技术上很困难。问题是:Git中有没有办法处理这种情况呢?我的意思是,我只想执行“git checkout 分支”而不会出现用户权限问题。

I have a Git project that it's a bit special because the files in the tree are generated by two different users. Example:

# ls -la

drwxr-xr-x 13 ivan ivan  4096 2012-02-02 16:52 .
drwxrwxrwx 32 root root  4096 2012-01-28 21:37 ..
drwxr-xr-x  2 ivan ivan  4096 2012-02-07 20:41 system
drwxr-xr-x  2 ivan ivan  4096 2012-02-07 20:41 compatibility
drwxr-xr-x 33 ivan ivan  4096 2011-12-08 18:13 resources
drwxr-xr-x  8 ivan ivan  4096 2012-02-07 20:41 .git
-rw-r--r--  1 ivan ivan   307 2012-02-02 16:52 .gitignore
-rw-r--r--  1 bulk bulk   700 2011-11-01 20:10 base.log
.....

Git is controled just by one user (ivan) but a daemon produces files assigned to bulk user. Everything was well whilst the daemon added new files, but when the daemon changed a file, git stopped working saying:

error: unable to unlink old 'base.log' (Permission denied)

I know the best option is to make the daemon run as ivan user, but that's technically difficult. The question is: is there any way to deal with this kind of situations in Git? I mean, I just want to do "git checkout branch" without having problems with user permissions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

颜漓半夏 2025-01-09 23:43:38

将您的 git 用户 (ivan) 添加到“bulk”组。

Debian:

sudo adduser ivan bulk   # and relogin

其他(FC、Redhat 和类似的?):

usermod -a -G bulk ivan

一切都应该没问题。要具有写访问权限(即,您可以签出、合并工作树等),请更改权限以允许组写访问权限:

sudo chmod g+rw bulk.log

替代方案:

Add you git user (ivan) to the 'bulk' group.

Debian:

sudo adduser ivan bulk   # and relogin

Others (FC, Redhat and similar?):

usermod -a -G bulk ivan

Everything should be fine. To have write access (i.e. so you can checkout, merge etc. you working tree), change permissions to allow the goup write access:

sudo chmod g+rw bulk.log

Alternatives:

夏夜暖风 2025-01-09 23:43:38

这实际上并不是一个 Git 问题,但为了给您一个答案...

您在存储库中创建文件,然后以不具有完全权限的用户身份运行工具。您必须解决其中一个问题:以批量方式运行 Git,或者创建 ivan 可以读写的文件。请注意,这并不一定意味着由 ivan 拥有 - 他们可能拥有 664 权限以及适当的组。

当然,另一个解决方案是不跟踪您没有权限的文件。您正在跟踪日志文件,这很可疑 - 这不是正常的用例,因为运行时生成的内容会根据您所在的位置而有所不同,因此对于应该签入的内容没有明确的概念 - 但我相信您实际上需要这样做。

因此,假设您确实需要跟踪这些文件,那么根据您当前的设置,就无法使事情正常进行。您无法写入您无权写入的文件。

This isn't really a Git question, but for the sake of giving you an answer...

You're creating files in your repository, and then running a tool as a user that doesn't have full permissions for them. You have to fix one problem or the other: run Git as bulk, or create files that ivan can read and write to. Note that that doesn't necessarily mean owned by ivan - they could have 664 permissions, with an appropriate group.

The other solution, of course, would be to not track the files that you don't have permissions for. It's suspicious that you're tracking log files - that's not a normal use case, since things generated at runtime will be different depending on where you are, so there's no solid notion of what should be checked in - but I'll trust that you do actually need to do it.

So assuming that you do need to track those files, there is no way to make things work given your current setup. You can't write to files you don't have permission to write to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文