806

Yeah learned this the hard way.

top 50 comments
sorted by: hot top controversial new old
[-] cmhe@lemmy.world 17 points 1 day ago* (last edited 22 hours ago)

Isn't it the exact opposite?

I learned that you can never make a mistake if you aren't using git, or any other way for having access to old versions.

With git it is really easy to get back to an old version, or bisect commits to figure out what exact change was the mistake.

The only way I understand this joke is more about not wanting to be caught making a mistake, because that is pretty easy. In other methods figuring out who did the mistake might be impossible.

[-] AeonFelis@lemmy.world 12 points 1 day ago* (last edited 1 day ago)

This is not about mistakes in the Git-managed code. This is about mistakes in the Git commands themselves. Anything that involves merging/rebasing/conflict resolution can potentially be botched. These mistakes are usually fixable, but:

  1. Fixing it requires some Git proficiency behind the level of the common Git user.
  2. If you don't catch it in time, and only find the mistake when it's deep in your layers of Git history - well, good luck.
[-] LePoisson@lemmy.world 4 points 22 hours ago

Went to tech elevator boot camp, was a decent experience even if I don't find myself doing exactly what I was expecting to do. Life is that way though.

Anyways, my first week I fucked some git stuff up so bad I became the go to guy when anyone had any git issues because I had to learn so much to undo my egregious error. I don't remember now exactly what it was but it took some serious git magic to sort.

Just saying that point 1 is very true. And yeah don't make mistakes in git.

[-] rikudou@lemmings.world 2 points 23 hours ago

Like accidentally committing multi-GB files and years down some poor mf (me in this case) has to figure out how to clear the files from history because the server is running out of space.

[-] offspec@lemmy.world 1 points 21 hours ago

Short of manually deleting .git you can always find any commit, you can walk backwards through your reference lof if it comes to it, the only real risk is throwing out unstaged changes.

load more comments (1 replies)
[-] fibojoly@sh.itjust.works 3 points 1 day ago

You're confusing errors in your code, and errors while doing some git command you thought you knew. Lucky you, it's clearly never happened to you because you don't mess around with it.

[-] cmhe@lemmy.world 1 points 22 hours ago* (last edited 22 hours ago)

Sure, I sometimes messed up with git, but a git reset , checkout, rebase or filter-branch (In the extreme cases) normally fixes it, but real issues are very rare. And I use git a lot... But only the CLI, maybe people have issues with GUIs?

[-] AeonFelis@lemmy.world 5 points 21 hours ago
[-] ezterry@lemmy.zip 1 points 20 hours ago

Funny those are commands I avoid.. They all have to do with editing history which I know there is a vocal group here that loves "clean" history but that isn't what happened.

sure merge full features so you can roll back a feature.. And if something is really off I might start from a snapshot commit and cherry pick/merge a bunch in but usually history is histoy.. If submitting to a public project I may make a new branch with the cleaned version but why edit in line. That is risking issues.

[-] isVeryLoud@lemmy.ca 4 points 21 hours ago

git reflog is your friend

The worst thing you could do is delete your local git repo.

[-] QuizzaciousOtter@lemmy.dbzer0.com 43 points 1 day ago* (last edited 1 day ago)
  1. Use git for any code you write. Yes, even a simple script.
  2. Commit and push often. More often than you think is reasonable. You can always rebase / fixup / squash / edit but you can't recover what you didn't commit.
  3. ???
  4. Profit.

Seriously, once you commited something to the repo it's hard to lose it. Unless you delete .git. But a this point frequent pushing has your back.

I know git can be hard to grasp in the beginning. It was hard for me too. I highly encourage everyone to put in the effort to understand it. But if you don't want to do that right now just use it. Just commit and push. It will pay off.

[-] Rooster326@programming.dev 8 points 1 day ago* (last edited 1 day ago)
  1. (3) Get annoyed by constantly increasing Code Coverage Requirements on untestable (often legacy) code. Even afding comments requires code coverage go up! Line must always go up!
  2. Change step 2 to "Commit and push ONLY when absolutely necessary. Because adding comments often requires a rewrite of untestable code."
  3. Go back to Step 2 and wait for a major bug.
[-] QuizzaciousOtter@lemmy.dbzer0.com 1 points 11 hours ago

3 is not related to using git in any way. I'm not really sure what you mean in 4. I didn't mean making a lot of changes, I meant that you should not wait with committing until you have a finished feature / fix / whatever. Commit after each refactor, commit after adding a new testable unit. It's always better to have more checkpoints. If your team does code review, they will appreciate atomic commits too.

[-] fibojoly@sh.itjust.works 2 points 1 day ago* (last edited 1 day ago)

Our company "architects" decided we needed 80% coverage minimum. On a mostly .Net 4.8 codebase. Hundreds of programs used in prod, with barely any tests in sight.
It's a fucking nightmare.

[-] ExperiencedWinter@lemmy.world 2 points 1 day ago* (last edited 1 day ago)

Why would you care about code coverage requirements on a branch that is currently in development? My work in progress commits might not build because they don't even compile, let alone have passing tests. The only time I care about the build passing and meeting requirements is when I'm ready to create the pull request.

Also code coverage is a useless metric, but that's a different story.

[-] Ephera@lemmy.ml 137 points 1 day ago

I've had juniors who didn't believe this, so just to say it: If you know what you're doing, practically any Git problem is recoverable.

The one major exception is if you delete your local changes before committing them.

[-] sorter_plainview@lemmy.today 50 points 1 day ago

Yeah.But many of them are extremely annoying. Specifically screwing up rebase. It is recoverable, but very annoying.

That said I have seen juniors make two other common mistakes.

  1. Pushing your commit without fetching
  2. Continuing on a branch even after it was merged.

I'm fed up with these two. Yesterday I had to cherry-pick to solve a combination of these two.

[-] psycotica0@lemmy.ca 38 points 1 day ago* (last edited 1 day ago)

Maybe I'm just a wizard, or I don't know what y'all are talking about, but rebases aren't special. If you use git reflog it just tells you where you used to be before the rebase. You don't have to fix anything, git is append only. See where the rebase started in reflog, it'll say rebase in the log line, then git reset --hard THAT_HASH

Pushing without fetching should be an error. So either they got the error, didn't think about it, and then force pushed, or someone taught them to just always force push. In either case the problem is the force part, the tool is built to prevent this by default.

Continuing after merge should be pretty easy? I'd assume rebase just does it? Unless the merge was a squash merge or rebase merge. Then yeah, slightly annoying, but still mostly git rebase -i and then delete lines look like they were already merged?

[-] sorter_plainview@lemmy.today 18 points 1 day ago

See all this is fine for someone with good experience in git. They know how to solve the screw up. But wih junior devs, who don't know much about it, they will just get confused and stuck. And one of the senior has to involve and help them solve. This is just annoying because these can be avoided very easily. Until they understand the pattern of how everyone operates with git, it just creates issues.

To me first time causing this issue is completely fine. I will personally sit with them and explain then what went wrong and how to recover. Most of them will repeat it again, act clueless and talk like they are seeing this for the first time in their life. That is the difficult part to me.

May be I'm just old school, and a grumpy old person, even though I'm not that aged.

[-] psycotica0@lemmy.ca 2 points 16 hours ago

Oh, the human interaction is annoying! Yeah gotcha. That makes more sense!

load more comments (1 replies)
load more comments (6 replies)
load more comments (11 replies)
[-] sucoiri@lemmy.world 3 points 1 day ago

Fun fact! If you added a file but never committed it you can still recover it with git fsck --lost-and-found. The changes were still added to the git object store, and by grepping through the dangling blobs you can find the object containing the changes you care about.

[-] BootLoop@sh.itjust.works 4 points 1 day ago

Does deleting the repo off disk and redownloading from remote considered recovering? If so I'm a git expert.

[-] toynbee@lemmy.world 5 points 1 day ago

Delete? Never.

mv git_repo git_repo.bad
[-] BootLoop@sh.itjust.works 3 points 1 day ago

I do this sometimes but then I forget about it and then node_modules in each repo fills my SSD.

load more comments (1 replies)
load more comments (6 replies)
[-] csm10495@sh.itjust.works 29 points 1 day ago

Special shout out to the person who committed a gigabyte memory dump a few years ago. Even with a shallow clone, it's pretty darn slow now.

We can't rewrite history to remove it since other things rely on the commit IDs not changing.

Oh well.

[-] pinball_wizard@lemmy.zip 3 points 1 day ago

Special shout out to the person who committed a gigabyte memory dump a few years ago. Even with a shallow clone, it's pretty darn slow now.

If you want to be the team's hero, I've had good luck removing old commits using git filter repo.

https://hibbard.eu/erase-sensitive-files-git-history-filter-repo/

We can't rewrite history to remove it since other things rely on the commit IDs not changing.

Oh right. Oof.

I would be working to arrange an accident for those other things. Those other things probably need to be retired.

[-] Michal@programming.dev 11 points 1 day ago

Sounds like a flawed workflow, if this didn't go through at least code review. Was it committed directly to master?

Curious to know what kind of system relies on hashed not changing? Technically the hashes don't change, but a new set of commits is made. The history diverges, and you can still keep the old master if you need it for some time, even cherry pick patches to it..

The guy at work who managed git before me, well didn't quite have the knowledge I do and was not using LFS. In one of the main repos a 200mb binary was pushed 80+ times. This is not the only file that this happened to. Even if you do a shallow clone, you still need to add the commit depth eventually. It's a nightmare.

load more comments (4 replies)
[-] Lushed_Lungfish@lemmy.ca 3 points 1 day ago

Oi ya gits, everyone knows da best way to fix a mistake is ta smash it's zoggin' 'ead in!

[-] Anafabula@discuss.tchncs.de 25 points 1 day ago

With Jujutsu (which is compatible with git), you can just

jj undo
[-] JustTesting@lemmy.hogru.ch 15 points 1 day ago* (last edited 1 day ago)

Been using it for over a year now and not being scared of trying operations is such a boon. It helps so much with learning when you know you can just roll back to an earlier state.

I've had zero issues with it so far and no one at work noticed anything different, other than there being a bit more rebase spam on PRs.

[-] umfk@lemmy.world 9 points 1 day ago

That is so cool. Why doesn't git have this already?

[-] kata1yst@sh.itjust.works 10 points 1 day ago

I mean, by definition, it does. It just involves parsing through the git log and a bunch of unintuitive, archaic commands.

load more comments (1 replies)
load more comments (2 replies)
[-] elbiter@lemmy.world 4 points 1 day ago

I just commit and push in the same line, all the time. Whenever I have to undo a change, I go to GitHub/Gitlab browse for the previous version and paste from there.

I definitely know is not the intended way to do this, but it works for me and has saved my ass several times.

[-] thatradomguy@lemmy.world 1 points 20 hours ago
[-] sik0fewl@lemmy.ca 49 points 1 day ago
[-] squaresinger@lemmy.world 30 points 1 day ago

git re-flog is what you do with those idiots who mess up the repo so that someone else has to come in and fix it again.

load more comments (13 replies)
[-] kibiz0r@midwest.social 31 points 1 day ago

Git repository operations are (almost?) always recoverable. git reflog is your friend.

The filesystem operations are another story. Handle with care.

load more comments (6 replies)
[-] marcos@lemmy.world 27 points 1 day ago

You know... A version control system... That class of software that makes it possible for you to recover from any error you commit.

load more comments (1 replies)
[-] Eiri@lemmy.ca 16 points 1 day ago

As long as you never touch the rebase button, you'll be fine. Probably.

[-] GissaMittJobb@lemmy.ml 14 points 1 day ago

Don't be afraid of rebases, they are an essential tool in Git.

This particular fear can only be addressed by understanding.

[-] pupbiru@aussie.zone 9 points 1 day ago
load more comments (12 replies)
load more comments
view more: next ›
this post was submitted on 06 Oct 2025
806 points (96.6% liked)

Programmer Humor

26772 readers
2972 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS