7 ms·
A git off my lawn moment: Every time I see someone complaining because they have to dive into the reflog to fix their own mistake, all I can hear is "I was oper
by falcolas 9y ago
A git off my lawn moment: Every time I see someone complaining because they have to dive into the reflog to fix their own mistake, all I can hear is "I was operating my table saw without using a push stick and can't understand why I lost a thumb".
Friends don't let friends (especially those who don't learn how to use their tools) rewrite shared git history. If you don't understand rebase, amends, etc can do to your (and everyone else's) repo, DON'T DO IT.
- AlexCoventry 9y agoOn the other hand, doing it is the only way you're going to learn. Just do it in a safe environment, with a snapshot of the repository.
- flowardnut 9y agopracticing safe version control is better than abstinence
- pretentiousPear 9y agoI see what you did there...
- jsmthrowaway 9y agoYep. That is the important tip, right here. $ pushd .. $ cp -a my-project my-project-before-I-did-git-surgery $ popd Then relax. This is extremely important before playing with nasty Git surgical tools such as huge rebases. Borked it up? $ pushd .. $ rm -rf my-project $ cp -a my-project-before-I-did-git-surgery my-project $ popd Undo is a great thing, and it's also important to triple check the entire state of the repository before you push, because pushing is basically committing to whatever surgery you've done. If you're having to fix stuff with -f, you're going to run into trouble; try to avoid -f ever.
- palunon 9y ago>If you're having to fix stuff with -f, you're going to run into trouble; try to avoid -f ever. I disagree. I don't have much experience using git with big teams, but at least for small team where a developer usually owns a feature branch, force pushing to the branch to take into account criticism on commits can be helpful. Of course, in that case, feature branches are considered non shared. Git own "next" branch is actually force pushed to all the time, to remove patches which didn't make the cut for example.
- falcolas 9y agoPersonal opinion - re-reviewing a pull request when someone has erased all context from your last review of that PR via a rebase and force push is a royal PITA. Especially for changes that span more than a few files. Did they address your concerns? The only way to know is to go back through all of the changes on that feature branch, and hope you don't miss anything. This, in contrast with just reviewing the latest commit, potentially going back to the rest of the changes with an eye towards the latest commit. It frankly bugs the piss out of me when people rebase and ask me to review their latest changes - it feels disrespectful of my time.
- gwright 9y agoI've taken to making the change as a fixup commit and leaving it in the PR for code review. Then when the changes are approved a quick `git rebase -i --auto-squash` cleans everything up before merging the branch back into `develop`.
- jsmthrowaway 9y ago> force pushing to the branch to take into account criticism on commits can be helpful Hm? Criticism on commits should be additive. The commit was made, response was made, and a new commit addresses the response. Rewriting history breaks a lot of things and removes context. Another approach: 1) Add commit addressing criticism. 2) Squash when merging feature in to master, which is one of the only cases where I think rewriting history is OK. Much cleaner master history, no rewriting history (which you should never do once another checkout sees your branch, including GitHub), and a number of other benefits. If you're routinely force pushing feature branches, something is broken in your workflow, IMO.
- swalsh 9y agorebase can be dangerous, but so productive. I think it's important to teach new devs how to properly use it. Especially if you're working in a continuous deployment environment, where you may need to quickly revert something.
- madeofpalk 9y agodriving can be dangerous, but so productive. I think it's important to each new adults how to properly use it.
- Nullabillity 9y agoYou already have git-revert, for reverting commits without rewriting history.
- swalsh 9y agoYou're misunderstanding the purpose i'm describing. Imagine 100 commits a day, maybe more. (I worked at a company that averaged 500 or more commits a day to the master branch. There were 1000 developers working in a monorepo). Some code is out in production, and suddenly we realize a specific commit is causing a problem. The idea here is to revert the commit as soon as you can, and then spend your time fixing it. When reverting code is easy, and the company has good logging to identify problems, you can deploy more often. It's a good thing. But to enable this "revert-first" culture, you have to design your commits to basically be super easy to revert. That means no merges in the master branch, you want to keep your revision history as clean as possible. One commit, as little dependencies as possible. Rebase is the right tool to use for this. The goal is a tidy linear history.
- Yokohiii 9y agoThat sounds quite chaotic and impossible to keep stable. I wonder who was responsible to find problems and fix the master after messing up?
- 9y ago
- leggomylibro 9y agoReminds me of a time I saw a funny Makefile mistake. SRCS contained both .cpp and .c files, and someone copied a recipe that only replaced .c ones. Then they used the resulting variable in 'make clean'. That was more of an, 'oh shit, git pull' sort of thing though.
- Groxx 9y agoRewriting shared history fits the metaphor pretty well. But you can still chop off your thumb in your local history, and that's safe to fix - you just have to know where the duct tape is.
- azernik 9y agoI use the reflog all the time to fix my own rebase mistakes; it's just on rebasing I've done locally, and where the results haven't made it out to a shared repo.
- rkangel 9y agoThis is a place where Mercurial wins out. Hg has the concept of phases that makes it much harder to screw up rewriting history: https://www.mercurial-scm.org/wiki/Phases https://www.mercurial-scm.org/wiki/Phases
- falcolas 9y agoReplacing a table saw with a circular saw (bad analogies abound) doesn't remove the opportunities for losing appendages. Especially for those who don't learn how to use the tools put in front of them. "It is impossible to make anything foolproof because fools are so ingenious." Yes, Git is a sharper tool with fewer blade guards than other version control systems, including HG. That sharpness and relative lack of safety mechanisms, however, lets you do things you can't in other systems. The real problem is that folks use these tools without attempting to understand them and cargo-cult onto a workflow which leaves them open to screwing things up. To continue the "git off my lawn" moment - I've had to use the reflog exactly zero times in the past few years, despite using rebase locally on a fairly frequent basis (and sadly remotely to fix other's bungles as well). This is only because I respect git for its sharp edges, and when it comes time to re-write history with rebase, I work carefully.