1

I have a bash script that iterates (forward in time) through a git repo. I have a curr_hash variable that represent the current hash, and I want to end my loop when curr_hash is the latest commit (which means that I can't iterate forward in time anymore). How do I do this?

Alon
  • 616
  • 1
  • 7
  • 18
  • 2
    That's a really really bad way to do it. Instead, do `git rev-list --all --reverse`, that will get you a timestamp-ordered list of commits, latest last. – jthill Aug 06 '19 at 01:37

1 Answers1

0

Assuming you want to move forward on a specific branch (because you know which branch your current commit is part of), you can use git rev-list --topo-order as in here or there.

git rev-list --topo-order curr_hash ..<yourBranch>

You can then reverse that list, and loop in the proper order.

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755