5 Jun 2011, 12:37pm
Git: commit Git hard head reset source control workflow
by bseanvt

leave a comment
Git: commit Git hard head reset source control workflow
by bseanvt
leave a comment
How to Remove Your Last Git Commit
Remove your last commit (if you haven’t pushed yet)
git reset --hard HEAD~1
To see changes that have been committed and their position in HEAD
git reflog
And to undo your previous reset and advance the cursor to the reference immediately behind the current state
git reset --hard HEAD@{1}
If you have already pushed you can
git revert HEAD
which will reverse your last commit by creating a new commit
Repost
This post is inspired by
http://pupeno.com/blog/really-resetting-the-database/#comment-1179. But as my blog mostly serves as a reference for my future self, I’d like to reprint this little snippet of code here as well.
namespace :db do
desc "Crush and burn the database"
task :hard_reset => :environment do
File.delete("db/schema.rb")
Rake::Task["db:drop"].execute
Rake::Task["db:create"].execute
Rake::Task["db:migrate"].execute
Rake::Task["db:seed"].execute
if !Rails.env.test?
Rake::Task["db:data"].execute
end
end
desc "Generate sample data for developing"
task :data => :environment do
# Create the sample data in here
end
end


