5 ms·
> At a previous company, there was an “infamous” commit in our main repository. The commit was about 10 years old, and it replaced every tab with 4 spaces. If
by pdw 5y ago
> At a previous company, there was an “infamous” commit in our main repository. The commit was about 10 years old, and it replaced every tab with 4 spaces.
If have commits like this, add the ids to a file `ignorerevs`, and then tell git about it:
git config --local blame.ignoreRevsFile ignorerevs
Then at least `git blame` will still give useful results. (This is a relatively new git feature, added a year or two ago.)
- catlifeonmars 5y agoNice! Is there a way to check this into a repository (a la .gitigore)?
- banana_giraffe 5y agoYou can specify a file with of such commits with --ignore-revs-file, and of course check in that file. Naming that file .git-blame-ignore-revs seems to be a convention I've seen more than once. Still need to specify the file yourself, so hopefully someone can point out the missing magic to have git pull in .git-blame-ignore-revs on its own.
- NegativeLatency 5y agoA shell alias?
- karlding 5y agoThat's what the blame.ignoreRevsFile [0] config option is for. [0] https://git-scm.com/docs/git-config#Documentation/git-config.txt-blameignoreRevsFile https://git-scm.com/docs/git-config#Documentation/git-config...
- IshKebab 5y agoYes but you can't check set git config from a repo unfortunately because some things in it would cause security issues. banana_giraffe was asking for a way to set it up automatically so users don't have to do anything.
- bhaak 5y ago10 years ago would probably long enough ago to not care for me. But wouldn’t the standard -w be enough to ignore most of this commit. But I used ignoreRevs in repositories that messed up their history by using an automatic indenter with atrocious settings.
- gumby 5y agoUnfortunately -w won't help you with patch, which uses character positions. But certainly helps with searching.
- harikb 5y agoIn addition, if their code is python, -w would incorrectly ignore legitimate changes
- jrochkind1 5y agodo you have a realistic example?
- contravariant 5y agoA simple one would be: total = 0 for value in list: total += value return total vs. total = 0 for value in list: total += value return total
- jrochkind1 5y agoah, fixing a bug, ok. I was trying to think of two hypothetical correctly functioning programs identical but for whitespace, and thinking that was probably pretty rare.
- contravariant 5y agoWell the first one simply returns the first value of the list, which can be correct. I just gave the variables names that turned this into a bugfix.
- nickysielicki 5y agoDepending on the size of the team and how much agreement you can get on the importance of such a change, I think the better way to do this on an older repository is to get everyone to nuke their checkouts and use git-filter-branch to rewrite the history so that nobody ever used tabs. https://stackoverflow.com/questions/58042532/how-can-i-clang-format-my-whole-git-history https://stackoverflow.com/questions/58042532/how-can-i-clang...
- azernik 5y agoJust git blame -w to ignore whitespace. There's also an equivalent git config option.
- shepherdjerred 5y agoWow, this is incredible! I convinced my team to adopt Prettier for many of our repositories. The only real criticism was that our git history would be cluttered since it would reformat all of our code. This seems like the perfect solution.
- erik_seaberg 5y agoWhen our code was well formatted and reviewed by professionals to show intent, I do not want a robot tampering with it for no good reason, especially if it blindly makes big diffs out of small changes.
- forrestthewoods 5y agoWho gives a shit about a single commit that converts tabs-to-spaces? How is this a problem in any way? The real problem here is that “git blame” is a garbage tool. Perforce has “timelapse view” that is radically better than any historical view I’ve seen in Git/Hg. With respect to this issue, git just needs to suck less.
- xmprt 5y agoYou answered your own question. Git blame is a pretty crappy tool but it's a tool that a lot of people use nevertheless. If you have a commit that converts tabs to spaces, then the blame for pretty much every single line will be lost before that point.
- forrestthewoods 5y agoDoes Git not offer a way to view the blame from an earlier version? This would let you skip past the wall. My company has a web tool for browsing the repo that allows this. It’s still inferior to Perforce timelapse view. But it’s not a hard blocker.
- hilbertseries 5y agoYea, you just have to checkout the version of that file from before the white spaces commit. Then run git blame on it.
- BrandonM 5y agogit blame WS_COMMIT^ -- FILE You’ll need to change the file name, though, if it’s been renamed since the whitespace change.
- cerved 5y agoyes of course, instead of git blame HEAD file you just specify whichever ref you want
- davidbludlow 5y agoThis looks like a job for https://akrabat.com/ignoring-revisions-with-git-blame/ https://akrabat.com/ignoring-revisions-with-git-blame/ That says to list all the annoying commits in a file, then use a new-ish (Git version 2.23) Git feature to ignore all those commits when doing git blame. Notice that one of the comments in that article says how to get everyone to use that ignore file, when using GitLens with VSCode.