How to undo last Git commit?

flint
Tags: Git
Answer this Question

Answers

1 total
jimlynch
Vote Up (17)

2.4 Git Basics - Undoing Things
http://git-scm.com/book/en/Git-Basics-Undoing-Things

"Undoing Things
At any stage, you may want to undo something. Here, we’ll review a few basic tools for undoing changes that you’ve made. Be careful, because you can’t always revert some of these undos. This is one of the few areas in Git where you may lose some work if you do it wrong.

Changing Your Last Commit
One of the common undos takes place when you commit too early and possibly forget to add some files, or you mess up your commit message. If you want to try that commit again, you can run commit with the --amend option:

$ git commit --amend
This command takes your staging area and uses it for the commit. If you’ve made no changes since your last commit (for instance, you run this command immediately after your previous commit), then your snapshot will look exactly the same and all you’ll change is your commit message.

The same commit-message editor fires up, but it already contains the message of your previous commit. You can edit the message the same as always, but it overwrites your previous commit."

Ask a question

Join Now or Sign In to ask a question.
Amazon plans to expand its small online ad delivery business enough to take on Google's AdWords, according to a Wall Street Journal report.
Bethany Mayer, who led Hewlett-Packard's foray into the growing field of network functions virtualization, has left the company to run network testing and optimization company Ixia.
Google has acquired Gecko Design, which will become part of the Internet company's unit developing cutting-edge products like Glass and balloons for Internet access.
Oregon has filed a long-expected lawsuit against Oracle over its role developing the state's troubled health insurance exchange website, alleging the vendor fraudulently induced Oregon to pay hundreds of millions of dollars for software and services that didn't work as promised.
It took some time and considerable internal effort, but SAP says it has made good on a pledge to simplify its software pricing and licensing model.
Widely accepted projections of a shortage of mobile spectrum may not be as dire as many analysts in the mobile and tech sectors are making it out to be, according to a new study.
It's a good – no, make that great – time to become an IT recruiter.
California's Department of Motor Vehicles is tapping the brakes on our robotic future, requiring all self-driving cars to include full human controls during testing.
Most people start thinking about retirement when they turn 70, if they haven't already called it a career. Not Oracle CEO Larry Ellison, who passed that milestone Sunday.
A U.S. lawmaker wants to rebrand the term net neutrality because its definition is confusing to many people.

White Papers & Webcasts

Webcast On Demand

Cloud BI Overview: Jaspersoft for AWS

Sponsor: TIBCO Jaspersoft

Webcast On Demand

Cloud BI in Action: Recorded Webinar of Customer, Kony, Inc.

Sponsor: TIBCO Jaspersoft

See more White Papers | Webcasts

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

randomness