Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Git history is intended to be immutable when working with others.

That's another pet peeve (though maybe less git's fault): immutable, yes, but then rebase is pushed quite liberally. Arguably not by git itself, but by many online learning resources.

It's convenient, and mostly works, but then occasionally really stings you.

...yet undoing the last commit, arguably the least aggressive of history-rewriting commands, remains awkward.



Rebasing has a simple rule: it is perfectly fine as long as you haven't shared those commits.*

Perhaps git should have a "checked rebase" command that requires a `--force` flag if there's an upstream branch set.

*And even then it's kind of okay as long as no one else has made commits on top of the rebased commits.


It's also very wise to make sure you disallow force pushing to master/main/production. If you force push to a topic branch, it's usually ok. If you accidentally overwrite someone's changes, it's because you are working together and you can communicate that you messed up and for them to `pull --rebase` or however you want to resolve it. Usually that is. There's always room for disaster :)


> Usually that is. There's always room for disaster :)

For me, this is where the problem with got lies. I use so many of it's commands infrequently enough that I don't know where the weird disastrous edge cases are, where I should use.

I think git would greatly benefit from a topical man page; a list of common and uncommon situations that shows the recommended commands for solving them, and explains what those commands do. I know that hundreds of random "guides" exist, but are they outdated, are they cannon, do they have bugs? When your UI is esoteric, situational documentation is really important.


Ya, the git UI is not great. It has improved a ton over the years but still not great. Have you ever seen Git Koans? It's good for a laugh. https://stevelosh.com/blog/2013/04/git-koans/


--force-with-lease

Which BTW I learned it exists when magit switched "p -f u" to use it instead of plain --force.


Oh right. I always neglect to do that mostly out of laziness of typing it out on the command line. It's funny, though, I maintain a branch plugin for vim (it's a fugitive extension) and I recently accepted a PR to switch `--force` to `--force-with-lease` yet I still don't do it. I need to start doing it!


How is "git reset HEAD~" "awkward"? It's not obviously named, but as was noted above, if there was git-uncommit, it would need every option that git-reset has, and so it would just be an alias, without the final argument.

"History is immutable" is generally accepted as describing the contents of commits, not their id's or relative ordering.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: