Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove commits that are not connected to the branch

Tags:

git

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

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.

I have tried:

git reflog expire --expire-unreachable=now --all
git gc --prune=all --aggressive

git rebase [hash]

But nothing seems to work.

like image 354
Patrik Avatar asked Oct 22 '25 06:10

Patrik


1 Answers

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?

like image 172
Vampire Avatar answered Oct 24 '25 01:10

Vampire