Reader small image

You're reading from  Git for Programmers

Product typeBook
Published inJun 2021
PublisherPackt
ISBN-139781801075732
Edition1st Edition
Right arrow
Author (1)
Jesse Liberty
Jesse Liberty
author image
Jesse Liberty

Jesse Liberty is a full-time hands-on programmer, specializing in C#, git and .NET MAUI. He hosts the popular Yet Another Podcast and is the author of more than a dozen best-selling programming books. Liberty is a Certified Xamarin Developer, a Xamarin MVP and a Microsoft MVP. He was a Technical Evangelist for Microsoft, Distinguished Software Engineer at AT&T; Software Architect for PBS and Vice President of Information Technology at Citibank, and he was on the teaching staff at Brandeis University. Jesse is a recognized expert and has spoken at conferences world-wide.
Read more about Jesse Liberty

Right arrow

You need to undo changes made in a commit

All you need to do here is to call the log, get the ObjectID of the commit you want to undo and call:

git revert ObjectID

Let's go back to the log:

Figure 12.3: Log, starting point

Now let's revert the commit that added the hello message:

git revert c507abf

Because I reverted a change in the middle of the branch, it's no surprise that I run into a merge conflict:

Figure 12.4: Merge conflict

To solve this I will call git mergetool, invoking the tool I set up in Chapter 4, Merging, Pull Requests, and Handling Merge Conflicts. Kdiff3 is smart enough to fix all the conflicts without my help:

Figure 12.5: Kdiff3 fixes the conflicts for me

Sure enough, when we open Program.cs the Hello World is gone:

Figure 12.6: Program.cs after revert

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Git for Programmers
Published in: Jun 2021Publisher: PacktISBN-13: 9781801075732

Author (1)

author image
Jesse Liberty

Jesse Liberty is a full-time hands-on programmer, specializing in C#, git and .NET MAUI. He hosts the popular Yet Another Podcast and is the author of more than a dozen best-selling programming books. Liberty is a Certified Xamarin Developer, a Xamarin MVP and a Microsoft MVP. He was a Technical Evangelist for Microsoft, Distinguished Software Engineer at AT&T; Software Architect for PBS and Vice President of Information Technology at Citibank, and he was on the teaching staff at Brandeis University. Jesse is a recognized expert and has spoken at conferences world-wide.
Read more about Jesse Liberty