Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I checked out a version different than HEAD. Let's say I made some commits, and so an anonymous branch was created. Afterwards I may have checked out a different branch, so now the only way to get to my commits is via reflog. If do this:

>> git reflog | grep -i mycommit
>> git branch reattaching
>> git cherry-pick hash_of_commits
>> git checkout master
>> git merge reattaching

Is it the equivalent of:

   >> git reflog | grep -i mycommit
   >> git branch reattaching sha1hash
   >> git checkout master
   >> git merge reattaching

What happens to the detached head commits, as I think that via cherry-picking, they will exist in 2 places. Will they forever remain in my repository?

share|improve this question

After cherry-picking, the old commits will still be there, and won't be purged while you still have a reflog pointing at them. One of the things git-gc does is remove old entries from reflogs-- so after 60 days, or whatever, those commits will become entirely dangling and will get GC'd.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.