this post was submitted on 25 Sep 2024
893 points (97.3% liked)
Programming
17119 readers
165 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I spent like 3 hours yesterday deduplicating two functions that were hundreds of lines long and nearly identical. I should probably learn how to use that git command that can diff two files on disk. Luckily I actually enjoy cleaning up code sometimes.
If you're using a decent development system, you'll have an executable called
diff
installed already :)That's what the
diff
tool is for.If you use VSCode, open both files and then ctrl-shift-P "Compare active file with ..."
You're welcome.
Thank you! I love VS Code
Dunno what OS's it supports besides Windows but I use Kdiff for random comparisons regularly, I think it works pretty well untill you get to much larger files (20+ MB slows down a lot). The huge file wasn't code but needed to check output changes for those curious.
I constantly check git comparison with previous versions to see what changed to break things in a build though. Didn't know there was a way to diff any files in git,should probably just learn to use that one.
Git uses the
diff
binary under the hood (unless you configure it to use something else).You can invoke that directly with
diff file_a.txt file_b.txt
.VS Code's diff tools are killer. Comparison is smarter than most, and you can edit either file as you go.
And if you want to avoid the Microsoft stank, there's VS Codium that has been de-Microsoft'd, like Chrome vs. Chromium.
git diff —no-index before.json after.json > showmethegoods.diff
You don’t have to save it to a file but I often do.
You can use a diff app directly such as meld which is free. Highly recommend.