gpt4 book ai didi

linux - root 到 git pull 作为另一个用户的脚本

转载 作者:IT王子 更新时间:2023-10-29 01:09:21 24 4
gpt4 key购买 nike

我有一个脚本,我想在另一个用户的 git 目录中执行 git pull。该脚本由 root 用户运行。例如:

cd /home/username/GitProject
sudo -u username -i git pull

当我运行它时,我得到:

fatal: Not a git repository (or any of the parent directories): .git

有没有办法让我的脚本以 username 的身份执行 git pull?

最佳答案

尝试不使用 sudo 的 -i 选项。该选项被记录为首先更改为目标用户的主目录,这会撤消您之前如此仔细所做的目录更改。或者,使用适当的 git 选项指定目录,如下所示:

sudo -u username -i git --git-dir=/home/username/GitProject/.git --work-tree=/home/username/GitProject pull

关于linux - root 到 git pull 作为另一个用户的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19872235/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com