How to undo last Git commit?

flint
Tags: Git
Answer this Question

Answers

1 total
jimlynch
Vote Up (12)

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.
National security may be at stake as private businesses try to manage a growing number of cyberthreats, but IT professionals shouldn't have to bear that burden alone.
Five music labels have filed a lawsuit against streaming music service Pandora Music, saying the company is violating state law by refusing to pay labels and artists for its use of recordings made before 1972.
Advanced Micro Devices' bottom line changed from black to red on Thursday when the company posted a loss after two straight quarters of profits.
Fifty billion devices will connect to the Internet in the next few years. It's up to vendors to make sure they do, in fact, connect to the Internet -- and provide reliable data, security and customer experience. Otherwise, analysts warn, the future may bring an Internet of Broken Things.
Building health insurance exchanges proved to be much, much easier said than done. Here's a quick look at who succeeded and who failed.
Oracle is gearing up for a fight with officials in Oregon over its role developing an expensive health insurance exchange website that still isn't fully operational.
Taiwan Semiconductor Manufacturing Co. said its net profit in the first quarter increased by 21 percent year-over-year on better than expected demand for smartphone chips.
SAP reported a strong growth in cloud revenue and fast adoption of its HANA platform in the first quarter, while its software revenue dipped from the same quarter in the previous year.
In their new role as brokers and consultants, CIOs will be in an even more powerful positions. According to a new survey, about two-thirds of C-level executives and business unit leaders expect the IT department to have more influence on technology decisions in the future.
During a week in which everyone seemed to be searching for answers amid revelations of the Heartbleed bug, several universities and their partners announced new efforts to explore IT security advances.
Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+