2

I have an old project that I was trying to clean up, and somehow I endedup with two separate commits that think they're the "initial commit" and don't have a parent branch, as seen below:

% git log --all --date-order --pretty="%h  %p  %d"   
    0fb2623  81d3553   (HEAD -> master, tag: v6.2.5, origin/master, 
origin/HEAD)  
    81d3553  d7d7578   (tag: v6.2.4)  
    d7d7578  eae8973   (tag: v6.2.3)  
    eae8973  ded0fe9   (tag: v6.2.1)  
    ded0fe9  efb33b0   (tag: v6.2.0)  
    efb33b0      
    13a5b0e  45ab2ba   (tag: v6.0.1)  
    45ab2ba  2d60f30    
    2d60f30  2185112    
    2185112  872f408    
    872f408    

Is there a way that I can re-link that in so that efb33b0 has a parent of 13a5b0e?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Gargoyle
  • 9,590
  • 16
  • 80
  • 145
  • `efb33b0` and `872f408` are two root commits. They don't have any parent. This is not a problem. Why would you like to "re-link"? – ElpieKay Nov 15 '17 at 03:34
  • Because it makes things confusing if I try and rebase, for example, as it can't go into that older set of commits. That second set is old enough I'd never use it again. Is there a way to just delete those last 5 commits then and actually have the efb33b0 be the true root? – Gargoyle Nov 15 '17 at 03:36
  • I just removed the v6.0.1 tag from my local repository and that whole second tree disappeared. Nice :) – Gargoyle Nov 15 '17 at 03:39
  • Check out a new branch from tag v6.0.1 and `git cherry-pick efb33b0^..master`, all the commits will be merged into the new branch with one line. – Itachi Nov 15 '17 at 03:43
  • You don't have to remove `v6.0.1`. You use `--all` so all the refs are listed. Add `--not v6.0.1` to `git log` and the history of `v6.0.1` is not shown. `v6.0.1` seems an orphan history. It doesn't have relationship with other tags/branches. You could just leave it alone. It's okay to delete the tag if you really don't need it any more. – ElpieKay Nov 15 '17 at 03:48

1 Answers1

0

I just removed the v6.0.1 tag from my local repository and that whole second tree disappeared

You can still make a new branch on 13a5b0e

Is there a way that I can re-link that in so that efb33b0 has a parent of 13a5b0e?

Create a graft file, and then filter-branch (better in this instance as git replace, as I mention here)

echo "efb33b0 13a5b0e  >> .git/info/grafts
git filter-branch 13a5b0e ..HEAD
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250