Or sql
Programmer Humor
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
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
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.
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.
- Pushing your commit without fetching
- 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.
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?
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.
Oh, the human interaction is annoying! Yeah gotcha. That makes more sense!
- Use git for any code you write. Yes, even a simple script.
- 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.
- ???
- 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.
- (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!
- Change step 2 to "Commit and push ONLY when absolutely necessary. Because adding comments often requires a rewrite of untestable code."
- Go back to Step 2 and wait for a major bug.
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.
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:
- Fixing it requires some Git proficiency behind the level of the common Git user.
- 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.
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.
git reflog
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.
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.
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..
With Jujutsu (which is compatible with git), you can just
jj undo
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.
That is so cool. Why doesn't git have this already?
I mean, by definition, it does. It just involves parsing through the git log and a bunch of unintuitive, archaic commands.
Git repository operations are (almost?) always recoverable. git reflog
is your friend.
The filesystem operations are another story. Handle with care.
You know... A version control system... That class of software that makes it possible for you to recover from any error you commit.
git reflog is your friend
The worst thing you could do is delete your local git repo.
As long as you never touch the rebase button, you'll be fine. Probably.
Don't be afraid of rebases, they are an essential tool in Git.
This particular fear can only be addressed by understanding.
I don't understand it. Every time I see something about a rebase it's some purist telling me it's "cleaner". Never got it to do what it says on the tin, and never hit a situation that I couldn't solve using more straightforward tools like merge.
What's your mental model for a Git commit, and a Git branch?
Once I properly learned those two concepts, understanding rebases became a lot easier.
I'll try to explain it to the best of my abilities.
- Think of a commit being a patch - a description of how to take a particular file from one state to another
- A branch is a list of patches to be applied in order, from the point where the branch was created until the last commit on the branch
When you rebase a particular branch, what you're essentially doing is taking all of the commits that are currently on your branch, checking out the other branch, and then applying each of the patches in order on that new branch.
A rebase can be cleanly applied if the premise for each commit has not changed when applied, but if the premise has changed, you get a conflict to be resolved before being able to continue the rebase.
I mentally model a rebase a bit as a fast version of how it would look like to build the branch I was on, but on top of the branch I'm rebasing on.
That's a good explanation of what it's supposed to do. That was how I understood it as well.
But anytime I've tried it, I've ended up with conflicts where there shouldn't be (like, I already solved that conflict when I merged earlier) and/or completely undesirable results in the end (for instance, some of my changes are just NOT in the result).
So I just gave up on the whole feature. Simpler to just merge the source branch into mine.
Depending on how structured your commits have been, it can either be very difficult to get a rebase through or a complete breeze. There are some features to make it easier - rerere
being the main one I'm thinking about.
Is that what interactive rebase tools use?
I don't do CLI git
You enable it using git config
, after that it will apply to whatever frontend you're using.
…button
Skill issue