How to undo last Git commit?

flint
Tags: Git
Answer this Question

Answers

1 total
jimlynch
Vote Up (20)

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.
In a copycat PC industry, Dell is trying to attract attention with the innovative features and technology firsts that it is bringing to PCs and tablets.
Online volunteers from more than 80 countries around the world are participating in the fight against the deadly Ebola virus disease, which has killed over 2,400 people in West Africa.
Google has to improve its settlement terms in an antitrust investigation over its search practices or face charges, following opposition from some quarters to the deal, the European Commission's competition chief Joaquin Almunia said Tuesday.
At a time when Web and mobile technology development have become top priorities, effective enterprise architecture matters more than ever. Here are this year's six winning initiatives
To fill out its cloud services portfolio with policy and auditing controls, Ericsson is acquiring a majority stake in San Francisco enterprise services company Apcera.
Lots of IT professionals participate on discussion forums that pertain to specific slices of the technology field, from Hadoop to Android development. What they might not realize is that while there, they are also elevating their presence in the recruiting community.
EMC spent almost a year discussing a merger with Hewlett-Packard and is weighing its options in light of the expected retirement of CEO Joe Tucci and shareholder discontent, according to a report in the Wall Street Journal.
A judge in New York has postponed for mediation proceedings a decision on an injunction motion by Getty Images against a Bing widget, which allowed publishers to embed image collages and slideshows from search results on their websites.
Increasingly stiff competition in the database market has claimed another victim, as InfiniDB has ceased operations effective immediately with plans to file for bankruptcy.
The U.S. Federal Communications Commission needs to create explicit rules that tell broadband providers what traffic management techniques they can and cannot use if the agency has any hope of enforcing its proposed net neutrality rules, some advocates told the agency Friday.
Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

randomness