Yeah learned this the hard way.

  • Primer - Zip@lemmy.zip
    link
    fedilink
    English
    arrow-up
    2
    ·
    2 days ago

    I hear people praise git reflog a lot, but when do y’all use this? Most I’ve ever needed is git log --graph for history checking. Maybe if I was in a situation where I knew the code on local branch X was working on Friday, but not anymore on Monday, then I could use git reflog to go back to Friday for that local branch right? Is that the idea?

    • Slotos@feddit.nl
      link
      fedilink
      arrow-up
      13
      ·
      2 days ago

      Power users rebase with squashes and fixups multiple times a day. Especially if the job’s integration process isn’t enforcing long living branches.

      Reflog is useful then, because you literally rewrite history every rebase.

    • chaos@beehaw.org
      link
      fedilink
      arrow-up
      4
      ·
      2 days ago

      I only use it when I’ve royally messed up and the commit I need to get back is no longer referenced anywhere. Accidentally deleted a branch, finished a merge or rebase before realizing I messed up, that kind of thing, just use the reflog to find it again, get a branch pointing to it, then try again.

    • panda_abyss@lemmy.ca
      link
      fedilink
      arrow-up
      5
      ·
      2 days ago

      It’s not often, but a bad git reset, or a messed up rebase of that branch that’s 8 months old that you’ve picked up again.

    • psycotica0@lemmy.ca
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      2 days ago

      git log will only show you commits in your history. If you’re only ever working forwards, this will contain all the stuff you’ll ever need.

      But if you’re rewriting history, like with a rebase or squash or something, or you’re deleting branches without merging them, then you can run into a situation where the official history of your branch doesn’t contain some of the commits that used to exist, and in fact still exist but are unlinked from anywhere. So reflog is the log of where you’ve been, even if where you’ve been isn’t in the official history anymore, so you can find your way back to previous states even if there isn’t otherwise a name for them.

      If all you care about is your current history, git can use the dates of commits just fine to see where you were on Thursday without needing the reflog.