PHP的Git类
个人编写,用PHP执行GIT命令 主要编写目地是利用git的push钩子访问该PHP能实现push触发自动部署 只实现了pull方法,其余方法可以以类似方法实现 ?php/** * Class Git * @author Jacky.Zhuo * @time 2015-11-01 *///Git操作类class Git { private $_path; priva
个人编写, 用PHP执行GIT命令
主要编写目地是利用git的push钩子访问该PHP能实现push触发自动部署
只实现了pull方法, 其余方法可以以类似方法实现
<?php /** * Class Git * @author Jacky.Zhuo * @time 2015-11-01 */ //Git操作类 class Git { private $_path; private $_projectName; private $_owner; private $_username; private $_password; private $_host; private $_suffix = 'git'; private $_isHttps = false; private $_url = ''; private $_log; private $_output; private $_descriptorspec; /** * 构造函数 * * 设置git参数 * * @param string $path 项目本地路径 * @param string $projectName 项目名 * @param string $owner 拥有者 * @param string $username 帐号用户名 * @param string $password 帐号密码 * @param string $host 项目所在地址 * @param string $suffix 项目后缀 * @param boolen $isHttps 项目协议是否为https * @param string $log 访问日志文件路径 * @param string $output 命令日志文件路径 * @return void */ public function __construct($path = __DIR__, $projectName, $owner, $username, $password, $host, $suffix = false, $isHttps = false, $log = false, $output = false) { $configFields = array('path', 'projectName', 'owner', 'username', 'password', 'host'); //设置项目信息 foreach($configFields as $field) { if(empty($$field)) { throw new Exception("{$field} is empty!"); return false; } $this->{'_' . $field} = $$field; } //设置路径协议 if($isHttps) { $this->_isHttps = true; } //设置项目后缀 if($suffix) { $this->_suffix = $suffix; } //设置log地址 if($log) { $this->_log = $log; } else { $this->_log = __DIR__ . '/git_log.txt'; } //设置git命令返回记录文件地址 if($output) { $this->_output = $output; } else { $this->_output = __DIR__ . '/git_output.txt'; } //设置git命令参数 $this->_descriptorspec = array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('file', $this->_output, 'a') ); //生成远程url $this->_createUrl(); } /** * pull方法 * * 从服务器中pull到本地 * * @param string $branch 默认为 origin master * @return boolen */ public function pull($branch = 'origin master') { $cmd = 'git pull ' . $this->_url . ' ' . $branch; return $this->_runCmd($cmd); } public function fetch() { } public function push() { } public function gclone() { } /* * 生成git地址url * * git地址格式 [https://][username]:[password]@[host]/[owner]/[projectName].[suffix] * * @reutrn void */ private function _createUrl() { $url = ''; //添加协议 if($this->_isHttps) { $url .= 'https://'; } else { $url .= 'http://'; } //添加用户名密码 $url .= urlencode($this->_username) . ':' . urlencode($this->_password); //添加地址 $url .= '@' . $this->_host . '/'; //添加项目地址 $url .= $this->_owner . '/' . $this->_projectName; //添加项目后缀 $url .= '.' . $this->_suffix; $this->_url = $url; } /* * log方法 * * 记录访问日志 * * @param string $msg 日志 * @return void */ private function _writeLog($msg) { $log = date('Y-m-d H:i:s') . ":\n"; $log .= $msg; $log .= "-------------------------------------\n"; file_put_contents($this->_log, $log, FILE_APPEND | LOCK_EX); } /* * 运行命令行 * * 该方法可以运行命令行, 并会自动记录命令行日志 * * @param string $cmd 要运行的命令行 * @return boolen */ private function _runCmd($cmd) { file_put_contents($this->_output, date('Y-m-d H:i:s') . ":\n", FILE_APPEND); $process = proc_open($cmd, $this->_descriptorspec, $pipes, $this->_path); if(is_resource($process)) { $output = stream_get_contents($pipes[1]); fclose($pipes[1]); } else { $output = 'no command'; } $returnValue = proc_close($process); file_put_contents($this->_output, "---------------------------------\n", FILE_APPEND); if($returnValue) { $this->_writeLog('Command faild.' . "\n"); return false; } else { $this->_writeLog('Command success: ' . $output); return true; } } } try { $git = new Git(__DIR__, 'project', 'owner', 'username', 'password', 'host', 'suffix', true); } catch(Exception $e) { echo $e->getMessage(); die; } $git->pull('test');

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP는 웹 개발 및 빠른 프로토 타이핑에 적합하며 Python은 데이터 과학 및 기계 학습에 적합합니다. 1.PHP는 간단한 구문과 함께 동적 웹 개발에 사용되며 빠른 개발에 적합합니다. 2. Python은 간결한 구문을 가지고 있으며 여러 분야에 적합하며 강력한 라이브러리 생태계가 있습니다.

PHP는 주로 절차 적 프로그래밍이지만 객체 지향 프로그래밍 (OOP)도 지원합니다. Python은 OOP, 기능 및 절차 프로그래밍을 포함한 다양한 패러다임을 지원합니다. PHP는 웹 개발에 적합하며 Python은 데이터 분석 및 기계 학습과 같은 다양한 응용 프로그램에 적합합니다.

phphassignificallyimpactedwebdevelopmentandextendsbeyondit

PHP는 1994 년에 시작되었으며 Rasmuslerdorf에 의해 개발되었습니다. 원래 웹 사이트 방문자를 추적하는 데 사용되었으며 점차 서버 측 스크립팅 언어로 진화했으며 웹 개발에 널리 사용되었습니다. Python은 1980 년대 후반 Guidovan Rossum에 의해 개발되었으며 1991 년에 처음 출시되었습니다. 코드 가독성과 단순성을 강조하며 과학 컴퓨팅, 데이터 분석 및 기타 분야에 적합합니다.

해결 : GIT 다운로드 속도가 느리면 다음 단계를 수행 할 수 있습니다. 네트워크 연결을 확인하고 연결 방법을 전환하십시오. GIT 구성 최적화 : 포스트 버퍼 크기를 늘리고 (GIT 구성-글로벌 http.postBuffer 524288000) 저속 제한 (git config --global http.lowspeedlimit 1000)을 줄입니다. git 프록시 (예 : git-proxy 또는 git-lfs-proxy)를 사용하십시오. 다른 git 클라이언트 (예 : Sourcetree 또는 Github 데스크탑)를 사용해보십시오. 화재 보호를 확인하십시오

GIT를 통해 로컬로 프로젝트를 다운로드하려면 다음 단계를 따르십시오. GIT를 설치하십시오. 프로젝트 디렉토리로 이동하십시오. 다음 명령을 사용하여 원격 저장소 클로닝 : git 클론 https://github.com/username/repository-name.git

GIT 코드를 업데이트하는 단계 : 코드 확인 : git 클론 https://github.com/username/repo.git 최신 변경 사항 가져 오기 : Git Fetch Merge 변경 사항 : GIT 병합 원산지/마스터 푸시 변경 (옵션) : Git Push Origin Master

git 저장소를 삭제하려면 다음 단계를 따르십시오. 삭제하려는 저장소를 확인하십시오. 로컬 리포지토리 삭제 : rm -rf 명령을 사용하여 폴더를 삭제하십시오. 원격으로 창고 삭제 : 창고 설정으로 이동하고 "창고 삭제"옵션을 찾은 후 작동을 확인하십시오.
