Most of us avoid dreaded git reset command — but actually it can be really useful, as long as you know how it works!
What does ...
For further actions, you may consider blocking this person and/or reporting abuse
My best use case for git reset is when I want to update my pull request, merge master and clean up the git history
git fetch
andgit merge origin/master
git reset --soft origin/master
same exact code in the repository but clean git historygit push --force
Pull Requests: a simple workflow
Jean-Michel Fayard 🇫🇷🇩🇪🇬🇧🇪🇸🇨🇴 ・ Dec 4 '17 ・ 2 min read
Interesting use case. So you're merging all of your pull requests commits into one commit. I can see that this makes the history cleaner. I personally like to keep that commit history in projects, especially for a big merge. It makes it easier to step back to a more specific point in the future after the merge. I can definitely see the benefits though :)
On GitHub you can do the same thing with merge and squash the commits.
The history in master is kept clean but you have a link to the pull request to see the details
Yeah it definitely makes sense, especially if you do lots of tiny commits then you would clutter the main branch :) I guess there is a balancing act though as to leaving enough commits to be able to cherry pick certain functionality in future (rather than looking at a pull request and manually doing things)
Thanks for this article @Charlotte, I want to underline that for your soft example,
git rebase
is also a very good choice.Thank you :) rebasing definitely is an option but reset works differently. Reset is much simpler if you just want to go to an earlier commit and forget about the commits after it.
Any other use for soft? Because for that use case I use rebase.
I guess resetting should be thought of more as when you want to totally undo your commits after a certain point and re-write them into a new commit message. With rebase you'd still have all the commits after that point there and you choose what you want to do with them (pick, squash, etc). So if you do not care about those commits, reset it the easiest option.
Ah yeah, makes sense so it is for situations where you want no witnesses of your crimes. :)
I've been using git for years, and I didn't know how git reset worked, maybe even forgot that it existed. I've cleaned up many a "git mess" though. It's always been, um "messy"!
I have had many instances where a knowledge of git reset would have been very useful.
Thanks for sharing!
And there's also good old plain
git reset
which only unstages the staged changes.The default is mixed :)
Good article, learned a bit more about GIT. Especially from the conversations.
Thanks for this! I have very rarely delved into using reset!