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.
The organizers of the FirstNet LTE public safety network have the frequencies and standards they need to build the system, and they know where the money's coming from. They know how to get there from here, but it won't be a quick trip.
IT leaders need to learn how to manage the evolving legal, privacy and compliance issues of SMAC contracts.
Financial institutions use many technologies to fight crime, but much of the work comes too late, focusing on suspicious activity, like uncharacteristic charges or money transfers, after it happens.
Nearly 90 percent of IT executives expect tech spending to either increase or hold steady. And only 12 percent report budget decreases.
A new survey of IT security professionals shows that many businesses are barely starting to exploit mobile technology, and some of them may be a mobile security nightmare waiting to happen.
California is moving its IT services to a cloud, on-demand, subscription-based service that state officials believe may meet as much as 80% of its computing needs.
Oracle database shops that have or are planning to download the latest version of 12c take warning: The vendor's newly launched, much-hyped in-memory processing database option is turned on by default, according to one expert.
Headphone maker Bose has launched a patent-infringement lawsuit against rival Beats Electronics, which Apple recently agreed to acquire in a US$3 billion deal.
The U.S. Securities and Exchange Commission has dropped its investigation into disclosures about Facebook advertising sales before the company went public in 2012.
Think CIOs in the U.S. are struggling with how to handle BYOD? IDC's John Delaney says it's much worse in Europe.
Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

randomness