如何删除分支并将所有提交推送到错误的存储库?

发布于 2024-10-19 20:59:58 字数 266 浏览 3 评论 0原文

我们有几个适用于 Android 项目的 git 存储库。我们有很小的“boot”存储库和很大的“android”存储库。在开发过程中,我们的一个人将分支从“android”推送到“boot”,现在启动存储库大小为 700 MB!无论如何,现在是否可以从“启动”中完全删除错误的分支以及与其相关的所有提交?

我尝试了过滤分支和其他方法,但大多数方法都更改了错误推送后的提交编号

理论上,删除“侧面”的提交应该不是问题。该分支从未合并到“master”,并且这些提交不是任何有用提交的父级

We have several git repositories working on Android projects. We have 'boot' repo which is small and 'android' which is huge. During development one of our guys pushed branch from 'android' to 'boot' and now boot repository size is 700 MB! Is there anyway to completely delete the wrong branch and all commits related to it from 'boot' now?

I tried filter-branch and other methods, but most of them change commit numbers made after that wrong push

In theory this shouldn't be a problem delete commits which are 'on the side'. This branch was never merged to 'master' and these commit are not parents to any useful commits

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻的味道 2024-10-26 20:59:58

使用 git push 从远程服务器删除分支

git push --delete boot branchname

之后,每个人都可以在其本地存储库上运行以下命令来删除已删除的分支。

git remote prune boot

不过,在删除分支后,默认情况下,数据仍将在每个存储库中保留 2-4 周,作为防止意外数据丢失的措施。如果磁盘空间问题对您来说确实很重要,那么可以尽快将其删除,但请注意,这将删除临时保留的所有无法访问的对象,以防止意外数据丢失。

git gc --aggressive --prune=now

Deleting a branch from a remote server is done using git push

git push --delete boot branchname

After this each person can run the following command on their local repo to remove the deleted branch.

git remote prune boot

After the branch is removed though, the data will still linger in each repository for 2-4 weeks by default as a measure to prevent accidental data loss. If the disk space concern is really that important to you, then it can be removed sooner but take note that this will remove all unreachable objects that are being kept temporarily to prevent accidental data loss.

git gc --aggressive --prune=now
吖咩 2024-10-26 20:59:58

删除分支是通过

git branch -D branch_name

注意大写的 -D 选项来完成的:这告诉 git 删除该分支,即使它没有完全合并到 master 中。

完成此操作后,使用 git gc 启动垃圾收集器。那么,你应该没问题。

Deleting the branch is done by

git branch -D branch_name

Note the capital -D option: this tells git to delete the branch even if it's not fully merged into master.

After doing that, fire up the garbage collector with git gc. Then, you should be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文