tags:

views:

59

answers:

2

Background: Swip was working on a test project solely for the purpose of trying out git. This is a local one-person repository that has not been shared so swip did a reset hard in order to obliterate some unwanted commits:

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

Then swip went along happily adding new commits to the project. Then, when swip looked at the graphical representation of the commit history, swip discovered that there appears to be an anonymous branch of the obliterated commits. It does not show up as a branch using git branch, but it does show up in the GUI.

alt text

Questions 1: How can swip get rid of this "anonymous branch" ... and what is swip really looking at here (the part in the red box)? What are some pointers to help swip understand what happened when swip did the hard reset so swip can better set swip's expectations.

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

+3  A: 

As mentioned in The illustrated guide to recovering lost commits with Git, you can recover "lost" commits (as in "no longer referenced by a branch or a tag").
That is why they still show up in gitk.
For instance, a:

$ git fsck −−lost-found

would also display them.

To clean this up (assuming you having nothing to get back from any other delete operations)

 $ git gc --aggressive
 $ git prune

See also git gc: cleaning up after yourself.


If that branch had been shared, a possible alternative would have been a git revert in order to make a new commit cancel the n previous ones.

VonC
+1  A: 

You can create some new branch by a commit.

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

git checkout -b my_branch 123e43e

Now your branch is non anonymous. You can merge or rebase it in your master branch

shingara