[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gits] Git question about local version diffs

On Fri, Feb 22, 2013 at 11:50:25AM -0700, Dan Reading wrote:
> How do I get a list of my local commits and display diffs.

The simplest commands to type which might give you output similar to
what you want are "git log" (a list of the most recent commits on
your current local branch), or "git log -p" (the same same thing with
diffs added).  Either way, you'll get the complete history, in
reverse chronological order.

> For example if I do a 'get status' it says that I'm 4 commits ahead of
> the master ( I have not done a 'git push' ).

If you want to restrict the output of "git log" so it shows you only
those 4 commits, you could do "git log origin/master.." instead
(which is shorthand for "git log origin/master..HEAD", i.e. show the
log starting going back as far as the branch named "master" on the
remote repository named "origin", all the way up to the head of the
local repository).  In your example, that would show you your 4 commits
only, newest first.

> I would like select two of the commits and see the diffs of the files.

If you know the ID of the commit (e.g. you are browsing through
"git log" where it shows them all), you can see its diff with just
"git show 0123456789abcd" or whatever (you need to give only enough
of the ID that it's unambiguous).  If you don't know the commit ID
but remember how many commits back you want to go, you could do
something like "git show HEAD^^" or "git show HEAD~4" (where all
the punctuation is shorthand for how many commits back you want
to go in the history).

If you know two commits and want to see the difference between them
(i.e. all one big diff, not broken down into individual commits)
then you can use "git diff" -- the syntax will be similar to the
previous examples (e.g. "git diff origin/master HEAD" or
"git diff HEAD~4 HEAD^^").

All of the above will help only if your changes have been committed
locally.  The easiest way to view uncommitted changes is "git status"
or plain "git diff" (without options).

You might also want to try browsing the history with different
tools entirely, e.g. gitk (comes with git) or giggle

Bye for now,
       Gary Wong      gtw at flux.utah.edu      http://www.cs.utah.edu/~gtw/