autoframe / git-exec-hook
Http git钩子调用用于fetch、pull、checkout、commit、push操作
1.0.1
2024-08-12 18:45 UTC
Requires
- php: >=7.4
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10
This package is auto-updated.
Last update: 2024-09-12 18:58:22 UTC
README
👨🏼💻 git-exec-hook
Http git钩子调用用于fetch、pull、checkout、commit、push操作
使用常量或构造函数参数进行配置
define('X_HUB_SIGNATURE','sha1 hook token'); //or use in AfrGitHook constructor define('X_HUB_SIGNATURE_256','sha256 hook token'); //or use sha 256 define('X_PATH_TO_GIT_REPO_DIR','path to current repo dir'); //or use in AfrGitExec constructor
`AfrGitHook` use Autoframe\GitExecHook\AfrGitHook; use Autoframe\GitExecHook\AfrGitExec; //Hook example $oGhr = new AfrGitHook('HOOK_TOKEN', '', true); $gitExec = new AfrGitExec(__DIR__ . '/origin'); //print_r($gitExec->setGitConfigDefault('autoframe','USER@gmail.com')); //print_r($gitExec->gitCloneWithUserToken('https://github.com/autoframe/hx','USER','ghp_TOKEN')); if ($oGhr->isPushOnMasterBranch()) { $aLog = $gitExec->allInOnePushCurrentThenSwitchToMasterPullAddCommitAndPush(); echo '<pre>'; print_r($aLog); echo '</pre>'; }
`AfrGitExec` use Autoframe\GitExecHook\AfrGitExec; $gitExec = new AfrGitExec('/PATH_TO_GIT_REPO_DIR'); echo '<pre>'; print_r( $gitExec->gitAddCommitAndPush( 'Manual commit ' . gmdate('Y-m-d H:i:s') . ' GMT', $gitExec->getCurrentBranchName() ) ); echo '</pre>';
🚀 在Cpanel / WHM上安装git 🤖
💻 Ubuntu
sudo apt update
sudo apt install git
git --version
💻 CentOS 8
sudo dnf update -y
sudo dnf install git -y
git --version
💻 CentOS 7
sudo yum update
sudo yum install git
git --version
⚙️ 配置
ssh / gpg / armor /指纹
ssh-keygen -o
📚 列出当前配置
git config --list
🛠️ 全局设置配置
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global core.logallrefupdates true
git config --global core.autocrlf false
git config --global core.symlinks false
git config --global core.bare false
git config --global core.ignorecase true
git config --global core.eol lf
🔧 将配置设置到当前项目
仅忽略--global
cd ~/some-dir/project-dir
🍀🌈🦄 克隆
cd ~/some-dir/project-dir
git clone git@github.com:autoframe/xxxx.git
git clone 'https://github.com/autoframe/xxxx.git'
⛔ 克隆私有仓库
为仓库创建一个新的令牌:https://github.com/settings/tokens
git clone https://user:TOKEN@github.com/autoframe/repo/
git clone https://user:TOKEN@github.com/username/repo.git
git clone https://oauth2:<YOUR-PERSONAL_ACCESS-TOKEN>@github.com/<your_user>/<your_repo>.git
git clone https://<pat>@github.com/<your account or organization>/<repo>.git
📄 之后,您可以执行以下两个步骤来标准化所有文件
git rm --cached -r . ⚠️ Remove every file from git's index.
git reset --hard ⚠️ Rewrite git's index to pick up all the new line endings.
git reset --hard HEAD~1 2>&1 ⚠️ Rollback commits back to head
❗⚠️ 重置命令
git checkout . #If you want to revert changes made to your working copy, do this:
git reset #If you want to revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!:
git clean -f #If you want to remove untracked files (e.g., new files, generated files):
git clean -fd #Or untracked directories (e.g., new or automatically generated directories):
git revert <commit 1> <commit 2> #If you want to revert a change that you have committed, do this:
🌐 从上游读取
git pull #Pull branch info
git fetch #Refresh branches
📥检出
git checkout master #Checkout master branch
git checkout -q master #Quiet, suppress feedback messages.
git checkout -f master #When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.
🙈检出参数
https://git-scm.cn/docs/git-checkout
-q, --quiet
静默,抑制反馈消息。
-f, --force
当切换分支时,即使索引或工作树与HEAD不同,也继续进行。这用于丢弃本地更改。
-b
git checkout -b new-branch-name
创建一个名为<new_branch>的新分支,并从<start_point>开始;有关详细信息,请参阅git-branch(1)。
-m, --merge
当切换分支时,如果您有一个或多个文件在当前分支和您要切换到的分支之间有所不同,则该命令将拒绝切换分支以保留您的修改。但是,使用此选项,将在当前分支、您的工作树内容和新的分支之间执行三方合并,您将处于新的分支上。
--ours, --theirs
当从索引检出路径时,如果遇到未合并的条目,不要失败;相反,忽略未合并的条目。
📤推送
git diff
git add .
git commit -m "#uztpOegQ comment info"
git commit -m "PROPT-6264 second commit"
git push <remote> <branch>
git push -u origin branch_name
🙈推送参数
https://git-scm.cn/docs/git-push
-u, --set-upstream
对于每个已更新或成功推送的分支,添加上游(跟踪)引用,由无参数git-pull[1]和其他命令使用。
-q, --quiet
除非发生错误,否则抑制所有输出,包括更新的引用列表。进度不会报告到标准错误流。
--all, --branches
推送所有分支(即refs/heads/下的引用);不能与其他。