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. |