从你的 Git 远程清理分支
项目描述
一个命令行工具,可帮助您清理已合并到 master 中的 Git 分支。
Git 最好的特性之一是便宜的分支。现有的分支模型,如GitHub Flow和 Vincent Driessen 的git-flow描述了使用此功能的方法。
问题
您的主分支通常是您所有代码所在的位置。所有特性分支都是短暂的,一旦完成就合并到主分支中。
随着时间的推移,您可以建立一长串不再需要的分支。它们已经被合并到master中,我们现在如何处理它们?
答案
使用git-sweep3您可以安全地删除已合并到 master 的远程分支。
要安装它,请运行:
pip install git-sweep3
自己试试(安全)
要查看 git-sweep 检测到的分支列表合并到您的主分支中:
您需要将 Git 存储库作为当前工作目录。
$ cd myrepo
预览命令不会对您的存储库进行任何更改。
$ git-sweep preview Fetching from the remote These branches have been merged into master: branch1 branch2 branch3 branch4 branch5 To delete them, run again with `git-sweep cleanup`
如果您对列表感到满意,您可以运行从远程cleanup中删除这些分支的命令:
$ git-sweep cleanup Fetching from the remote These branches have been merged into master: branch1 branch2 branch3 branch4 branch5 Delete these branches? (y/n) y deleting branch1 (done) deleting branch2 (done) deleting branch3 (done) deleting branch4 (done) deleting branch5 (done) All done! Tell everyone to run `git fetch --prune` to sync with this remote. (you don't have to, yours is synced)
注意:这可能需要一点时间,它正在通过电子管与遥控器通话。
您还可以为远程分支和主分支赋予不同的名称。
$ git-sweep preview --master=develop --origin=github ...
告诉它跳过它默认执行的git fetch。
$ git-sweep preview --nofetch These branches have been merged into master: branch1 To delete them, run again with `git-sweep cleanup --nofetch`
让它跳过某些分支。
$ git-sweep preview --skip=develop Fetching from the remote These branches have been merged into master: important-upgrade upgrade-libs derp-removal To delete them, run again with `git-sweep cleanup --skip=develop`
一旦 git-sweep 找到分支,系统会要求您确认是否要删除它们。
Delete these branches? (y/n)
您可以使用--force选项绕过它并立即开始删除。
$ git-sweep cleanup --skip=develop --force Fetching from the remote These branches have been merged into master: important-upgrade upgrade-libs derp-removal deleting important-upgrade (done) deleting upgrade-libs (done) deleting derp-removal (done) All done! Tell everyone to run `git fetch --prune` to sync with this remote. (you don't have to, yours is synced)
删除本地分支
您还可以使用简单的 hack 清理本地分支:
$ cd myrepo $ git remote add local $(pwd) $ git-sweep cleanup --origin=local
发展
git-sweep 使用git-flow进行开发和发布周期。如果你想和我们一起解决这个问题,请分叉项目并在完成后将拉取请求放入 开发分支。
要运行测试,请使用以下命令:
$ git clone https://github.com/talhajunaidd/git-sweep3 $ cd git-sweep $ poetry install ... $ poetry run tox
要求
git >= 1.7
Python >= 3.7 < 3.10.0
执照
友好的社区 MIT 许可证。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
git-sweep3-0.2.0.tar.gz
(11.6 kB
查看哈希)
内置分布
git_sweep3-0.2.0-py3-none-any.whl
(14.0 kB
查看哈希)
关
git_sweep3-0.2.0 -py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | ae0ba15f851a5226fdfaa27ffcd0bfb47753f8b5b591664d56b3b8292e390041 |
|
| MD5 | 648ca38f1eded53176ac1f3e6524c48b |
|
| 布莱克2-256 | 2eb8d3af709c18d384f87c943cea554196c48fb3cc17a25ee968b8c99f42f6e4 |