logoalt Hacker News

sevenzerotoday at 12:28 PM8 repliesview on HN

How is the history relevant? Honest question. 5 years in the field I never had a reason to check out the git history of any project I ever worked on.


Replies

flohofwoetoday at 3:08 PM

You never run a git blame or git bisect to find out when and under which circumstances a regression or bug was introduced, and why this specific change was made? That might work for a while on a personal project, but is essential in a team project. It's not uncommon that by fixing a bug you also accidentially undo an actually intended change. Doing some software archeology in the git history and tracing back the steps that led to the bug/regression usually prevents that sort of thing. You'd also want to notify the person who introduced the bug (and if this is a good and honorable chap, they'll fix the bug themselves).

simonwtoday at 2:43 PM

I look at history all the time.

Why is the code like this? Usually git blame will show me either a commit message with extra context or a link to an issue thread.

When was this bug first introduced? Git bisect can track it down almost automatically.

If you're never looking at history you're missing out on a lot of the value Git provides. It's more then just a backup tool.

cpuguy83today at 12:31 PM

Bug is uncovered. Where was it first introduced? Why was the code changed? What did it do before the bug was introduced?

show 1 reply
benruttertoday at 12:44 PM

Simple but pretty common use case: If you're ever looking at some pre-existing code and thinking "I don't really get why it's written like this?", you can get a lot out of looking through the git blame/history.

Often "weird design" is there for historic reasons around stuff like backwards compatibility. If your project has a well managed commit log, you can find the notes of whoever implemented it, possibly even with their motivation for doing so.

At the very least, you can find out who wrote that code and ask them about it.

There's a tonne of data in git histories - this article was shared a few months back and is an awesome example of some things you can do with git history: https://piechowski.io/post/git-commands-before-reading-code/

show 1 reply
Shatnerztoday at 12:35 PM

Checking git history is one of the first things I do when I find unfamiliar code or when I'm debugging something. Git history contains a lot of context that helps speed up the rest of the process

owaislonetoday at 12:49 PM

Enables the best git command ever: git bisect

show 1 reply
pastakatsutoday at 2:00 PM

You've truly never come across a single thing you've gone to "fix" only to have it break stuff and then explained why it needs to stay that way in a commit message?

taybintoday at 1:56 PM

There are several possible reasons for that, but I'll just say it's a very common use case. It's actually the one of the original use cases for SCSs. How else could you revert to a prior commit?