Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
sha1hash
>> 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
    sha1hash
   >> 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

1 Answer 1

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

 
discard

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.