<p>I'd like to script, preferably in rake, the following actions into a single command:</p>

<ol>
<li>Get the version of my local git repository.</li>
<li>Git pull the latest code.</li>
<li>Git diff from the version I extracted in step #1 to what is now in my local repository.</li>
</ol>

<p>In other words, I want to get the latest code form the central repository and immediately generate a diff of what's changed since the last time I pulled.</p>

[{'answer_id': 61004, 'author': 'Greg Hewgill', 'author_id': 893, 'author_profile': 'https://Stackoverflow.com/users/893', 'pm_score': 4, 'selected': False, 'text': '<p>This is very similar to a question I asked about <a href="https://stackoverflow.com/questions/53569/how-to-get-the-changes-on-a-branch-in-git">how to get changes on a branch in git</a>. Note that the behaviour of git diff vs. git log is inconsistently different when using two dots vs. three dots. But, for your application you can use:</p>\n\n<pre><code>git fetch\ngit diff ...origin\n</code></pre>\n\n<p>After that, a <code>git pull</code> will merge the changes into your HEAD.</p>\n'}, {'answer_id': 61477, 'author': 'Greg', 'author_id': 108, 'author_profile': 'https://Stackoverflow.com/users/108', 'pm_score': 4, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/questions/61002/how-can-i-generate-a-git-diff-of-whats-changed-since-the-last-time-i-pulled#61004">Greg\'s</a> way should work (not me, other Greg :P). Regarding your comment, origin is a configuration variable that is set by Git when you clone the central repository to your local machine. Essentially, a Git repository remembers where it came from. You can, however, set these variables manually if you need to using git-config.</p>\n\n<pre><code>git config remote.origin.url &lt;url&gt;\n</code></pre>\n\n<p>where url is the remote path to your central repository.</p>\n\n<p>Here is an example batch file that should work (I haven\'t tested it).</p>\n\n<pre><code>@ECHO off\n\n:: Retrieve the changes, but don\'t merge them.\ngit fetch\n\n:: Look at the new changes\ngit diff ...origin\n\n:: Ask if you want to merge the new changes into HEAD\nset /p PULL=Do you wish to pull the changes? (Y/N)\nIF /I %PULL%==Y git pull\n</code></pre>\n'}, {'answer_id': 62303, 'author': 'Lily Ballard', 'author_id': 582, 'author_profile': 'https://Stackoverflow.com/users/582', 'pm_score': 8, 'selected': True, 'text': "<p>You could do this fairly simply with refspecs.</p>\n\n<pre><code>git pull origin\ngit diff @{1}..\n</code></pre>\n\n<p>That will give you a diff of the current branch as it existed before and after the pull. Note that if the pull doesn't actually update the current branch, the diff will give you the wrong results. Another option is to explicitly record the current version:</p>\n\n<pre><code>current=`git rev-parse HEAD`\ngit pull origin\ngit diff $current..\n</code></pre>\n\n<p>I personally use an alias that simply shows me a log, in reverse order (i.e. oldest to newest), sans merges, of all the commits since my last pull. I run this every time my pull updates the branch:</p>\n\n<pre><code>git config --global alias.lcrev 'log --reverse --no-merges --stat @{1}..\n</code></pre>\n"}, {'answer_id': 2831146, 'author': 'Clintm', 'author_id': 3384609, 'author_profile': 'https://Stackoverflow.com/users/3384609', 'pm_score': 2, 'selected': False, 'text': "<p>If you drop this into your bash profile you'll be able to run grin (git remote incoming) and grout (git remote outgoing) to see diffs of commits that are incoming and outgoing for origin master.</p>\n\n<pre><code>function parse_git_branch {\n  git branch --no-color 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/\\1/'\n}\nfunction gd2 { \n echo branch \\($1\\) has these commits and \\($2\\) does not \n git log $2..$1 --no-merges --format='%h | Author:%an | Date:%ad | %s' --date=local\n}\nfunction grin {\n git fetch origin master\n gd2 FETCH_HEAD $(parse_git_branch)\n}\nfunction grout {\n git fetch origin master\n gd2 $(parse_git_branch) FETCH_HEAD\n}\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/61002', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4061/']