Quick Git - Time Qualifiers

post-thumb

Have you ever heard about time qualifiers in git? Basically, they enable us to specify a certain point in time to take into account when dealing with git references like branches. There’s much potential for time qualifiers in operations like git diff or even git checkout, where they can be used to track down bugs on when exactly they were introduced for example.

Time qualifiers can be appended to references like branches with the @{<TIME_QUALIFIER>} notation. Some valid time qualifiers are

  • @{0}
  • @{5.minutes.ago}
  • @{1.hour.ago}
  • @{1.day.ago}
  • @{2.weeks.ago}
  • @{3.years.ago}
  • @{yesterday}
  • @{2021-11-23.08:30:00}
  • @{1.day.12.hours.ago}

Say for example, you want to check if some bug has been present already before deployment last friday. It is now monday. To see how data.service.ts looked like on friday or respectively what has been changed in there since then, you can do

git diff develop@{3.days.ago} -- src/app/core/data.service.ts

or

git diff develop@{3.days.ago}..develop@{0} -- src/app/core/data.service.ts

Of course, you would never deploy on friday.

Speaking of this particular bug, you now want to go back to the commit before deployment to tinker around and investigate further. Sure, you could use git log to search the commit and use the hash directly. But it may be faster and more convenient to use a time qualifier for that, too.

git checkout develop@{3.days.ago}

Personally, I think time qualifiers are one of the lesser known features in git but can come in very handy especially in investigative situations, which is why I wanted you to know about them.

Lernen Sie uns kennen

Das sind wir

Wir sind ein Software-Unternehmen mit Hauptsitz in Karlsruhe und auf die Umsetzung von Digitalstrategien durch vernetzte Cloud-Anwendungen spezialisiert. Wir sind Microsoft-Partner und erweitern Standard-Anwendungen bei Bedarf – egal ob Modernisierung, Integration, Implementierung von CRM- oder ERP-Systemen, Cloud Security oder Identity- und Access-Management: Wir unterstützen Sie!

Mehr über uns

Der Objektkultur-Newsletter

Mit unserem Newsletter informieren wir Sie stets über die neuesten Blogbeiträge,
Webcasts und weiteren spannenden Themen rund um die Digitalisierung.

Newsletter abonnieren