删除所有不在主服务器上的提交 [英] Delete all commits not on master
问题描述
我有一个带有几个分支的本地git存储库.我想在本地删除所有非master分支以及不在master分支上的提交.如何删除不在master分支上的所有提交?
I have a local git repository with a couple of branches. I want to locally delete all non-master branches, as well as the commits that are not on the master branch. How do I delete all commits that are not on the master branch?
我后来做的一次选择失败,因为它到达了一个合并的提交,所以失败了,所以它有两个父母.我需要怎么做才能使其只有一个父级(来自master分支)?
I am later doing a cherry-pick that fails because it reaches a commit that was a merge, so it has two parents. What do I need to do so that it only has one parent (from the master branch)?
推荐答案
git branch | grep -v "master$" | xargs git branch -D
以上内容将获取所有分支,过滤出包含"master"的分支,然后将其删除.
The above will get all branches, filter out those that include "master", and then delete them.
当Git next做垃圾收集时,现在孤立的提交将被删除.如果要立即强制这种情况发生,可以运行:
When Git next does garbage collection, the now-orphaned commits will be deleted. If you want to force that to happen now, you can run:
git gc --prune=now --aggressive
这篇关于删除所有不在主服务器上的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!