|
1 |
| -# git-pwsh |
2 |
| -:octocat: 备份自己在VScode常用的操作git的PowerShell脚本 |
| 1 | +<div align="center"><a href="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/ChinaGodMan" target="_blank"> |
| 2 | + <img height="128px" width="128px" src="https://avatars.githubusercontent.com/u/96548841?v=4" alt="UserScripts"></a> |
| 3 | +</div> |
| 4 | +<img height=6px width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest"> |
| 5 | + |
| 6 | +# Git-便捷 PowerShell 脚本 |
| 7 | + |
| 8 | +> :octocat: 备份自己在 VScode 常用的操作 git 的 PowerShell 脚本 |
| 9 | +> |
| 10 | +> :octocat: 适用于 Windows 系统 |
| 11 | +> 搭配与`Vscode`更为方便 |
| 12 | +
|
| 13 | +> [!TIP] |
| 14 | +> |
| 15 | +> 单独在 PowerShell 运行需要先进入目录 |
| 16 | +> 可以将脚本目录放在环境变量中,直接运行 |
| 17 | +
|
| 18 | +添加到系统级变量之后就可以方便使用了: |
| 19 | + |
| 20 | +```powershell |
| 21 | +CreategitHubRepo |
| 22 | +``` |
| 23 | + |
| 24 | +```powershell |
| 25 | +$currentPath = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine) |
| 26 | +$newPath = "$currentPath;C:\git-pwsh" |
| 27 | +[Environment]::SetEnvironmentVariable('Path', $newPath, [System.EnvironmentVariableTarget]::Machine) |
| 28 | +``` |
| 29 | + |
| 30 | +<img height=6px width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest"> |
| 31 | + |
| 32 | +## CreateGitHubRepo.ps1 |
| 33 | + |
| 34 | +创建 GitHub 仓库并创建本地仓库设置关联 |
| 35 | + |
| 36 | +- `name`:仓库名称 |
| 37 | +- `private`:公开或私有 |
| 38 | +- `description`:仓库描述 |
| 39 | + |
| 40 | +```powershell |
| 41 | +.\CreategitHubRepo.ps1 -name "666666666666" -private $true -description "666666666666" |
| 42 | +``` |
| 43 | + |
| 44 | +<img height=6px width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest"> |
| 45 | + |
| 46 | +## DeleteBranch.ps1 |
| 47 | + |
| 48 | +删除本地和远程分支 |
| 49 | + |
| 50 | +- 提示输入需要删除的分支名称 |
| 51 | +- 回车后删除本地和远程分支 |
| 52 | + |
| 53 | +```powershell |
| 54 | +.\DeleteBranch.ps1 |
| 55 | +``` |
| 56 | + |
| 57 | +<img height=6px width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest"> |
| 58 | + |
| 59 | +## ForcePull.ps1 |
| 60 | + |
| 61 | +强制从远程拉取,并覆盖本地 |
| 62 | + |
| 63 | +```powershell |
| 64 | +.\ForcePull.ps1 |
| 65 | +``` |
| 66 | + |
| 67 | +## Login.ps1 |
| 68 | + |
| 69 | +```powershell |
| 70 | +.\Login.ps1 |
| 71 | +``` |
| 72 | + |
| 73 | +<img height=6px width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest"> |
| 74 | + |
| 75 | +## PushAllRepos.ps1 |
| 76 | + |
| 77 | +批量更新本地仓库到远程仓库 |
| 78 | + |
| 79 | +- 需要在脚本内配置本地`Vscode`工作区路径 |
| 80 | + |
| 81 | +```powershell |
| 82 | +.\PushAllRepos.ps1 |
| 83 | +``` |
| 84 | + |
| 85 | +<img height=6px width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest"> |
| 86 | + |
| 87 | +## SyncBranches.ps1 |
| 88 | + |
| 89 | +同步本地分支和远程分支,并删除失效的本地分支 |
| 90 | + |
| 91 | +```powershell |
| 92 | +.\SyncBranches.ps1 |
| 93 | +``` |
| 94 | + |
| 95 | +<img height=6px width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest"> |
| 96 | + |
| 97 | +## AutoPush.ps1 |
| 98 | + |
| 99 | +在仓库运行自动更新本地仓库到远程仓库 |
| 100 | + |
| 101 | +> [!WARNING] |
| 102 | +> |
| 103 | +> 为`force` 推送 |
| 104 | +
|
| 105 | +- `git add .` |
| 106 | +- `git commit` |
| 107 | +- `git push` |
| 108 | + |
| 109 | +```powershell |
| 110 | +.\AutoPush.ps1 |
| 111 | +``` |
| 112 | + |
| 113 | +<img height=6px width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest"> |
| 114 | + |
| 115 | +## BranchReset.ps1 |
| 116 | + |
| 117 | +重置分支到指定 `commit`,运行后提示输入`hash` |
| 118 | + |
| 119 | +- `0`: 保留更改并回退到指定提交 |
| 120 | +- `1`:丢弃更改并回退到指定提交 |
| 121 | +- `2`:回退到上一个提交 |
| 122 | + |
| 123 | +```powershell |
| 124 | +.\BranchReset.ps1 |
| 125 | +``` |
| 126 | + |
| 127 | +<img height=6px width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest"> |
| 128 | + |
| 129 | +## CreateBranch.ps1 |
| 130 | + |
| 131 | +创建一个分支并推送到远程仓库 |
| 132 | + |
| 133 | +```powershell |
| 134 | +.\CreateBranch.ps1 |
| 135 | +``` |
0 commit comments