Hacker News new | ask | show | jobs
by ekzy 3589 days ago
I agree with that. So you could undo step by step without thinking about the number to put next to your undo command. It seems a bit trickier to implement, though
1 comments

Only a bit of awk magic:

~/git-undo.awk:

  BEGIN { jmp = 0 }
  {
    match($2, "{([0-9]+)}", c);
    if (c[1] == jmp)
    {
      jmp++;
      if ($3 == "reset:")
      {
        match($6, "{([0-9]+)}", x);
        jmp += x[1];
      }
      else
        i--;
      if (i == 0)
      {
        print jmp;
        exit;
      }
    }
  }

  git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{$(git reflog | awk -v i=${1-1} -f ~/git-undo.awk)}; }; f'
Redo is also possible, but i don't have time now to do it.