Anonymous branch after executing git reset

Background: Trevor worked on a test project solely to test git. This is the local repository of one person that has not been split, so Trevor made reset hard to destroy some unwanted commits:

:git reset --hard 6aa32cfecf4 HEAD is now at 6aa32cf auto commit Sun Feb 28 16:00:10 -0800 2010 

Then Trevor happily added new commits to the project. Then, when Trevor looked at a graphical representation of the commit history, Trevor discovered that there seemed to be an anonymous branch of destroyed commits. It does not appear as a branch with a git branch, but it appears in the GUI.

Questions 1: How will Trevor get rid of this "anonymous branch" ... and what does Trevor really look at? What are some pointers that will help Trevor understand what happened when Trevor did a hard reset so that Trevor could better tune Trevor's expectations.

Questions 2: Assuming Trevor has shared the project with other people. What would be an alternative to do the same (or similar) without doing a hard reset?

+6
git branch reset
source share
2 answers

As mentioned in the Illustrated Guide to Recover Lost Commits from Git , you can recover the โ€œlostโ€ commit (as in โ€œno longer refers to a branch or tagโ€).
This is why they still appear in gitk.
For example, a:

 $ git fsck โˆ’โˆ’lost-found 

will also display them.

To clear this (assuming you have nothing to return from other delete operations)

  $ git gc --aggressive $ git prune 

See also git gc: cleanup after itself .


If this branch was split, an alternative could be git revert to make a new commit undo the previous ones.

+4
source share

You can create a new branch using commit.

If your last commit on your anonymous branch is 123e43, you can do:

git checkout -b my_branch 123e43e

Now your affiliate is not anonymous. You can merge or reinstall it in your main branch

+3
source share

All Articles