Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
C0D4669024yJust use git branch and spawn of based on the last healthy commit.
# git branch <branch-name> <commit>
For example:
# git branch develop 04c65f3
Then Git push -f back on top of master, both problems fixed.
You have a second branch, and a master that isn't destroyed 😅 -
Push your local master to a new branch and go from there. Afterwards configure the new/fixed master-branch as protected.
Also checkout ohshitgit.com -
Voxera113884y@theabbie yes. Force push an old branch when one has a local instance of it and no other branches with history exists and its gone.
But its hard to accidentally fo it if you are multiple people involved snd if they keep their own local branches around. -
@Voxera Force push is like code suicide, Fortunately, I won't lose any code because of any fuck-up and my stupidity.
-
Voxera113884y@foox I am not sure. Force push rewrites the branch but there might be safeguards for that, i have never had to check for them fortunately.
-
Voxera113884y@theabbie there is one acceptable case in my book.
If you have pushed a branch and need to make changes to replace something AND your the only one using the branch.
This case is to clean up commits since for history’s sake you do not need all the bug fixes from CR/PR.
But I know some prefer to keep the full history anyway and some are adamant that any non vital commits are squashed before merge to main.
I do not think there will ever be a real consensus on that ;) -
KDSBest7714y@Voxera @foox as long as you have your local rep. The ref log has still all commits even after a force push and 2000 hard resets.
-
Voxera113884y@KDSBest sure, as long as there are extra repos.
But if you force push to the main and have no other branch with history and no extra repo, the I think you are out if luck.
But I takes some dedicated focus to make so many mistakes ;) -
KDSBest7714y@Voxera not extra, your local, which you used to force push is enough. I gave git workshops about the deepest internals of git.
You will never lose anything you ever committed from your local repository. The only way is:
A) you tinker with your reflog
B) you got a detached head and you forcefully let git clean them up
When you commut something hard rebase to the commit before that and force push to any repository you want. The history is destroyed on the remote repos. But on your local one in your ref log the commit you deleted is still in the ref log and will stay there for eternity!
A branch is just a link to a commit so no need for extra branches also!
Related Rants
How to delete 16 days of commits 101 🤯:
First of all, me and my class (computer science in college) were working on a project for around 12 weeks, our “client” is one of our teacher and we literally just finished today to work on the project since our degree terminal projects are starting next week.
So now there's this guy in our class who kinda has the reputation to be stuborn and clumsy; he’s going to do his assigned task, commit, push it and put his task into QA (which is just peer evaluation and testing nothing really complex) and then when we try his functionality and finds out it isn’t working, we tell him and the only thing he always answers is : “but it works on my machine” and then we will need to explicitly ask him to be sure he has all the latest changes (database and codebase) and to see if it still works on his side since it doesn’t work for anyone else.
This actually happened quite a lot in these 12 weeks and you can definitely imagine that of course it would definitely not happen again today when we thought we were finally done with this project…
So another teacher gave us an assignment to create a development environment for our big project so we could try out Docker instead of virtual machines, he made GitHub Classroom repos with a minified version of our project and up to this point everything is fine and clear. That is until 3 hours ago, that our little clumsy friend somehow pushed his Docker related files on the main project, maybe he was trying his Docker setup on the real project no big deal you know EXCEPT IF HE HADN’T NOT PULLED SINCE 16 DAYS 😤.
He was doing maintenance on another project so I can maybe understand but gosh how did he not see the big warning of Git that he wasn’t up to date with master ? And yes we only have a master branch bear with us but hopefully we were able to create a new branch with the up to date project and then merge master.
A couple of us had a gut feeling that this guy would do something that would break the whole project right before we ended, turns out we were right 😅
rant
git