duangong0690 2014-07-17 22:39
浏览 87

为什么远程执行的git命令会影响原始服务器?

I have a php script that runs on one server, which includes an exec() of an ssh command to another server. That ssh command runs a script which includes git commands. The git commands in the remote file, executed on the remote server, seem to be affecting the server that originated the ssh command, leaving the originating server on the wrong git branch.

I have created two scripts to minimally reproduce this. The first script git_ssh_bug_repro_1.php prints out what its hostname and git branch are, then runs an exec()'ed ssh command of the second script on a different server (sudo ssh root@test-1 'php /path/git_ssh_bug_repro_2.php') and print_r's the output of that exec, then prints out again what its hostname and git branch are afterwards. The second script also begins by printing its hostname and current branch, then does git checkout testing, then prints out its hostname and branch again. The output of these two scripts running together as described:

root@abc-1:/path# php git_ssh_bug_repro_1.php
BEFORE running ssh command:
COMMAND: git rev-parse --abbrev-ref HEAD
Hostname: abc-1, current git branch: master
COMMAND: sudo ssh root@test-1 'php /path/git_ssh_bug_repro_2.php'
    Password authentication is disabled to avoid man-in-the-middle attacks.
    Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
    Switched to branch 'testing'
    OUTPUT:
    Array
    (
        [0] => master
        [1] => BEFORE running git checkout command:
        [2] => COMMAND: git rev-parse --abbrev-ref HEAD
        [3] => Hostname: test-1, current git branch: master
        [4] => COMMAND: git checkout testing
        [5] => OUTPUT:
        [6] => Array
        [7] => (
        [8] =>     [0] => master
        [9] =>     [1] => Your branch is ahead of 'origin/testing' by 21 commits.
        [10] => )
        [11] => AFTER running git checkout command:
        [12] => COMMAND: git rev-parse --abbrev-ref HEAD
        [13] => Hostname: test-1, current git branch: testing
    )
AFTER running ssh command:
COMMAND: git rev-parse --abbrev-ref HEAD
Hostname: abc-1, current git branch: testing
root@abc-1:/path#

SUMMARY: Why do git commands that are being run by a script on one server affect the git status of another server (in this case, causing it to switch to the wrong branch), just because said script was fired off from the other server via ssh? And how can I make it not do that so the originating server's git branch is not changed or otherwise tampered with?

  • 写回答

1条回答 默认 最新

  • dsy19811981 2014-07-18 17:39
    关注

    Yes, this turned out to be a false positive sort of problem. On both of the servers in question, the git repo directory turned out to by symlinked to the same location on the same server. So, of course changing the branch on one also changed it on the other - they're the same directory. Apologies for the misplaced question, and thanks to anyone who did take the time to look at this.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用