{"id":5692,"date":"2019-11-04T13:57:01","date_gmt":"2019-11-04T18:57:01","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=5692"},"modified":"2019-11-04T13:57:01","modified_gmt":"2019-11-04T18:57:01","slug":"reverting-a-single-file-with-git","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=5692","title":{"rendered":"Reverting a Single File with Git"},"content":{"rendered":"<p>Git revert is great for resetting the entire project to a particular state \u2013 I went down a bad path, really don\u2019t want to do this, and resetting to the state I was in this morning is <em>exactly<\/em> what I want to do. Sometimes, though \u2026 that\u2019s <em>not<\/em> the case. I added a couple of debugging lines to a file that I don\u2019t really need. Or I\u2019ve gone down a bad path <em>here<\/em> but have good work in a few other files too. In those cases, you can revert a <em>single<\/em> file to the latest committed version. Run \u201cgit status\u201d and \u201cgit diff\u201d to confirm that it is an uncommited change.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"979\" height=\"491\" class=\"wp-image-5693\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/11\/word-image.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/11\/word-image.png 979w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/11\/word-image-300x150.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/11\/word-image-768x385.png 768w\" sizes=\"auto, (max-width: 979px) 100vw, 979px\" \/><\/p>\n<p>To revert a single file to its latest committed state, use \u201cgit checkout \u2013 <em>filename<\/em>\u201d \u2013 you can see the added line has disappeared.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"979\" height=\"264\" class=\"wp-image-5694\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/11\/word-image-1.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/11\/word-image-1.png 979w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/11\/word-image-1-300x81.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/11\/word-image-1-768x207.png 768w\" sizes=\"auto, (max-width: 979px) 100vw, 979px\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git revert is great for resetting the entire project to a particular state \u2013 I went down a bad path, really don\u2019t want to do this, and resetting to the state I was in this morning is exactly what I want to do. Sometimes, though \u2026 that\u2019s not the case. I added a couple of &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[233],"class_list":["post-5692","post","type-post","status-publish","format-standard","hentry","category-coding","tag-git"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5692"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5692\/revisions"}],"predecessor-version":[{"id":5695,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5692\/revisions\/5695"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}