{"id":1148,"date":"2014-07-03T10:51:29","date_gmt":"2014-07-03T17:51:29","guid":{"rendered":"http:\/\/10kdev.net\/?p=1148"},"modified":"2014-07-03T11:20:02","modified_gmt":"2014-07-03T18:20:02","slug":"a-git-recipe-for-going-back-in-time","status":"publish","type":"post","link":"http:\/\/10kdev.net\/?p=1148","title":{"rendered":"A Git Recipe For Going Back In Time"},"content":{"rendered":"<p>The one thing I REALLY love about distributed version control is the ease of branching. There is nothing like it. If you are currently on SVN you know what a pain it is to check out another branch and switch your workspace over, or (gag) try to roll back your local. Not so wtih Git or Hg. Another thing I love is the simplicity to roll back to a previous pointin the code. Super easy, almost zero time.<\/p>\n<p>QA found abug in our code that was assigned to me with these conditions:<\/p>\n<ul>\n<li>Bug in QA deployment (released 2 weeks ago)<\/li>\n<li>Bug in DEV deployment (questionable release date)<\/li>\n<li>No bug in my development machine code.<\/li>\n<\/ul>\n<p>I couldn&#8217;t pinpoint any relevant fixes in the code with a ton of developers checking in on the same files and it looked like DEV code hadn&#8217;t been released since QA although the build engineer couldn&#8217;t answer that for me. \u00a0I dug through the build numbers and it made me more suspicious.<\/p>\n<p>Perfect scenario to branch, rollback, and test. So here were the steps I took from the command line:<\/p>\n<p>1. Made a branch to work in:<\/p>\n<p>git checkout -b oldCodeBranch<\/p>\n<p>2. Check the status to make sure I&#8217;m good, and on the branch:<\/p>\n<p>git status<\/p>\n<p>3. Listed the commits so I could grab a commit hash to roll back to:<\/p>\n<p>git log &#8211;pretty=format:&#8221;%H %cd %an %s&#8221;<\/p>\n<p>4. Roll the branch back to the hash, discarding any future changes:<\/p>\n<p>git reset &#8211;hard f8b720b2a3<\/p>\n<p>5. Build<\/p>\n<p>mvn clean install<\/p>\n<p>6. Debug<\/p>\n<p>A variation on steps 1-3 if you know the hash (maybe from Tortoise Git; still trying to figure out if Gitg is useful):<\/p>\n<p>git checkout -b oldCodeBranch f8b720b2a3<\/p>\n<p>So this solved my problem: \u00a0the bug was fixed but not yet deployed.<\/p>\n<p>I found the error right away; and that the DEV environment build hadn&#8217;t been released since the QA release (grrrr what&#8217;s the point of DEV then!!!). Then, switched back to master in the blink of an eye and deleted the branch. The speed at which I could accomplish this in Git with such little pain is awesome. Plus, for this particular project I am using git-svn to front the SVN repository, but once I get the code it is *all* in git-land until I push it.<\/p>\n<p>I want to stress something here: the speed an ease that I accomplished this task, compared to something like SVN. \u00a0Until a developer goes through these mundane daily tasks they can&#8217;t appreciate it and I do, now. \u00a0I really encourage using something that lets you branch and change around in your system with ease be it Git, Hg, or anything else.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The one thing I REALLY love about distributed version control is the ease of branching. There is nothing like it. If you are currently on SVN you know what a pain it is to check out another branch and switch your workspace over, or (gag) try to roll back your local. Not so wtih Git [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/1148"}],"collection":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1148"}],"version-history":[{"count":8,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/1148\/revisions"}],"predecessor-version":[{"id":1156,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/1148\/revisions\/1156"}],"wp:attachment":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1148"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}