{"id":253,"date":"2018-03-01T15:57:31","date_gmt":"2018-03-01T20:57:31","guid":{"rendered":"https:\/\/chasberndt.com\/?p=253"},"modified":"2018-03-01T16:01:58","modified_gmt":"2018-03-01T21:01:58","slug":"determined-files-changed-between-two-releases","status":"publish","type":"post","link":"https:\/\/chasberndt.com\/?p=253","title":{"rendered":"Determine What Files Changed Between Two Releases"},"content":{"rendered":"<p>I get asked this a lot. Luckily, Git makes it pretty easy to get this information, but sometimes you need to string together multiple commands to do this gracefully.<\/p>\n<p>Here&#8217;s the meat and potatoes:<\/p>\n<pre>git diff --name-only REVISION1..REVISION2 desired\/sub\/directory<\/pre>\n<p>What if you don&#8217;t have the revision\/commit but instead a branch name? And what if that branch name has a \/ in it? Well, you&#8217;ll find that this command fails. It throws a generic ambiguous argument error. How would you get around this? Easy! Find the revision\/commit of that branch. How? Check out the branch, make sure it&#8217;s the latest revision, and determine the revision\/commit ID.<\/p>\n<p>How this can be accomplished in Bash:<\/p>\n<pre>git checkout BRANCH\/NAME &amp;&amp; git pull origin BRANCH\/NAME\r\nREV_ID=$(git rev-parse HEAD)<\/pre>\n<p>But who added the file and what is the associated work item? STOP MOVING THE GOAL POST! Still, that&#8217;s fairly easy, too. Just pull the last commit to each file that&#8217;s returned in the diff command. Below is a simple Bash script that will generate this information:<\/p>\n<pre>BRANCH_A=release\/9.2.0.0\r\nBRANCH_B=release\/9.3.0.0\r\nREPO_DIR=\/path\/to\/cloned\/repo\r\nCHECK_DIR=sub\/path\/to\/desired\/dir\r\n\r\ncd $REPO_DIR\r\ngit fetch\r\n\r\ngit checkout $BRANCH_A &amp;&amp; git pull origin $BRANCH_A\r\nCOMMIT_A=$(git rev-parse HEAD)\r\n\r\ngit checkout $BRANCH_B &amp;&amp; git pull origin $BRANCH_B\r\nCOMMIT_B=$(git rev-parse HEAD)\r\n\r\nFILE_LIST=$(git diff --name-only $COMMIT_A..$COMMIT_B $CHECK_DIR)\r\n\r\necho \"FROM - $BRANCH_A\"\r\necho \"TO - $BRANCH_B\"\r\nfor FILENAME in $FILE_LIST;\r\ndo\r\n echo $FILENAME\r\n git log -n 1 --pretty=short -- $FILENAME\r\ndone<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I get asked this a lot. Luckily, Git makes it pretty easy to get this information, but sometimes you need to string together multiple commands to do this gracefully. Here&#8217;s the meat and potatoes: git diff &#8211;name-only REVISION1..REVISION2 desired\/sub\/directory What if you don&#8217;t have the revision\/commit but instead a branch name? And what if that <a class=\"read-more\" href=\"https:\/\/chasberndt.com\/?p=253\">&hellip;&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-git"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=253"}],"version-history":[{"count":4,"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":257,"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts\/253\/revisions\/257"}],"wp:attachment":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}