I have the following git branches: master and dev:
*master*
|
A--B--C
\--D--E
|
*dev*
After rebasing dev on master, I have:
*master*
|
A--B--C--D'--E'
\--D--E |
|
*dev*
So D and E remain in a 'dead branch'. How can I remove them?
So for example, if you rebase featureA branch onto your master branch, but you don't like the result of the rebase, then you can simply do git reset --hard featureA@{1} to reset the branch back to exactly where it was before you did the rebase.
To push the changes to the branch after a rebase, you need to force push your commits using the -f or --force flag in the git push command on Git. This is because something has changed in the remote branch and the commit history is different for both the remote and your local branch.
is because your rebased feature branch now has 25 new commits that aren't reachable from origin/feature (since they came from the rebase on master ) plus 2 commits that are reachable from origin/feature but have different commit IDs.
You don't need to: because commits D
and E
have no1 name pointing to them, they're eligible for "garbage collection". Eventually git will run a git gc
and throw them away for you.
If you want to speed this up, you can run git gc
yourself, but then footnote 1 comes into play. :-)
1This is not quite true. While the branch-name dev
now contains the ID of commit E'
(the copy), there are two reflog entries, one for dev
and one for HEAD
, that allow you (and git) to find commit E
. There is also a semi-special name, ORIG_HEAD
, which lasts until something else replaces its contents (another rebase, or a git merge
, for instance).
By default, most reflog entries persist for either 30 days or 90 days, depending on whether the commit is reachable from the current branch head. Once the reflog entry expires, then the object is a candidate for garbage collection.
As yet another precaution, git gc
leaves "loose objects" alone unless they are at least two weeks old (by default—this is configurable, and there is a --prune=
option to override this as well). So in general, for a nominally-abandoned object to go away, it:
(And of course, git gc
must run, although git automatically runs this whenever it "looks promising".)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With