With the right set of parameters, you can get the git log command to show you the history of just our single file: $ git log - index.html The first thing we have to find out is which exact revision we want to restore. That’s when you want to turn back time, but only for this specific file and not for the whole project! For example, you know that index.html was working fine at some earlier point in time, but now it’s not. Sometimes you’ll want to restore a specific file to specific revision. Resetting a Specific File to a Previous State After the process is finished, you can see that only the first, valuable chunk of changes survived - just like we wanted! You’ll notice that I typed “n” for the first chunk (in order to keep it) and “y” for the second chunk (in order to discard it). Git will then take you by the hand and ask you - for every chunk of changes in that file - if you want to discard it or not. Some of the changes we made in this file are actually great, while only some of them need to be undone.Īgain, git restore comes to the rescue - but this time with the -p flag, because we want to go down to the “patch” level: $ git restore -p index.html Our second problem in index.html is a little bit more tricky. But because git checkout has so many different jobs and meanings, I strongly prefer the slightly newer git restore command (which is focused solely on these types of tasks). Note that, alternatively, I could have used the git checkout command to achieve the same outcome. Let’s undo all of them and recreate the last committed state of that file: $ git restore css/general.css The changes we made went in a totally wrong direction. Let’s tackle the problem in general.css first. You don’t need Tower to follow along with this tutorial. Note: for a better overview and clearer visualization, I’m using the Tower Git desktop client in some of my screenshots. Let’s take a look at an example scenario with some “local” changes (aka changes we haven’t committed, yet). Here’s where Git can help you: it allows you to keep what’s good and discard the changes that you don’t want anymore. In other words: some of the code that you’ve produced is great … but some of it not so much. At times, it feels like you’re taking two steps forward and one step back.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |