删除未连接到分支的提交 [英] Remove commits that are not connected to the branch
问题描述
我想合并另一个仓库中的某些更改,所以我添加了远程,获取和合并的对象.但是我不认为会添加其他分支的提交.
I wanted to merge in some changes from another repo so I added the remote, fetched and merged. But I did not think that the commits of the other branch would be added.
我支持合并中的一次提交,并手动添加了更改的文件并推送了该提交.
I backed one commit from my merge and manually added the changed files and pushed that commit.
所以现在我在一个分支中有两个断开连接的提交树.像这样:
So now I have two disconnected commit trees in one branch. Something like this:
A-B-C-D-master
1-2-3-4
我只想删除1-2-3-4提交.我不在乎历史记录或任何子/父提交或文件.
我想保留所有历史记录中的A-B-C-D提交.
And I just want to remove the 1-2-3-4 commits. I don't care about history or any child/parent commits or the files.
I want to keep the A-B-C-D commits with all history.
我尝试过:
git reflog expire --expire-unreachable=now --all
git gc --prune=all --aggressive
git rebase [hash]
但是似乎没有任何效果.
But nothing seems to work.
推荐答案
如果没有引用指向 1
, 2
, 3
和 4
,它们悬空了,将被 gc
删除.
您还在哪里看到这些提交?
还是有些头或标签指向那些提交吗?
If no ref points to 1
, 2
, 3
and 4
, they are dangling and will be removed by gc
.
Where do you still see those commits?
Do still some heads or tags point to those commits?
这篇关于删除未连接到分支的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!