Quote:
Originally Posted by suzzer99
Thanks I'll check out some of those git strategies. Undo last commit is what I want - but it's not that simple I've found. I always try SourceTree reverse commit and revert commit and neither do exactly what I want. Then I get in trouble and almost lose my changes.
As far as our gitflow - basically master always represents what's in prod. We don't merge to master until after we put a release branch in prod and we're completely happy with it - like days later.
We may have lots of long-lived feature branches and a few long-lived release branches in development at any time. It's the responsibility of leads to constantly pull in master and
possibly other relevant branches that are scheduled to go into production prior to the one their working on.
Devs have their development branch(es) and it's their responsibility to always pull in the feature or release branch they're working on. Dev branch names are of this form: dev-suzzer-release-012209, dev-suzzer-supercoolnewfeature, dev-suzzer-bugfix10777, etc. This allows us to periodically prune old orphaned branches that start with "dev-".
Note this is monster website with a lot of manual smoke-testing and deploy steps. So YMMV.
One nice thing about release branches is if we found out something broke like 2 weeks after the release, I can do a dummy pull request (DMN- = DO NOT MERGE) between the previous release and the current one and scan over the diff for possible culprits. I guess you can do this with tags (which we hardly used but probably should have). But I really like the visual onsite diff of pull-requests, and ability to add comments, etc. Maybe I can still get that with tags?
undo last commit is just a soft reset. hard reset will undo the commit and lose the changes.
"git reset --soft HEAD~1" where 1 is the number of commits to undo. so if its just your last commit, use 1. then you can stash that commit and you will always have those changes. this is a pattern I use a lot.
also, if you have EVER committed something, no matter what you do, you will almost always be able to get it back with a "
git reflog". I say almost bc I am sure there are ways to mess it up but if you just undo the commit and then undo your changes or much up your changes or even do a hard reset, you can still just use the git reflog id to checkout that detached version. then do a git soft reset and bam your changes are no there in uncommitted state.
revert commit is strange in my experience and I avoid it. it creates a whole new commit that gets rid of your changes of the commit you specify. so I dont think it will do what you want bc it will never you leave you with your uncommitted changes existing. to do that you need to do a "git reset" at some point. I guess revert is nice bc it will leave in the history of the master branch the old changes so any developer can get to them (with a git checkout <commitId> then git soft reset last commit) so I can see why the revert makes sense to maintain the history. also, revert can undo a commit from long ago if necessary.