git notes main page | gitolite main page | license

IMPORTANT NOTE: although this page has a "gitolite.com" URL, this is not about gitolite. That's just an artifact of "sitaramc.github.com" being translated to "gitolite.com" and so ALL my git related stuff gets carried over. Gitolite documentation has another /gitolite in the URL, so you can tell. My apologies for this confusion.

slightly more advanced tips

how to remember what “…” does

Git’s “…” operator is confusing, because it does different things in git diff and git log. Here’s something that may help you reason it out.

To start with, these points are fundamental:

To those simple rules, add just one more (easy enough to remember): the “...” operator always involves the common ancestor somehow.

With those rules in mind, you can keep track of what the double-dot and triple-dot mean very easily.

Consider git diff A...B:

And this becomes git diff CA(A,B)..B, where CA(A,B) is the common ancestor of A and B. Easy enough?

Now look at git log A...B

So: git log CA(A,B)..A PLUS git log CA(A,B)..B

Easy way to remember what git reset’s soft/hard/mixed do

^^loosely based on https://gitster.livejournal.com/25150.html^^

Assume you start from a “everything is committed and golden” state. Let’s pretend you came to this starting point via a git checkout: and then you edit a bunch of stuff, compile/test, and then git add and git commit:

$ git checkout mywork
...edit edit edit...
$ git add ...
$ git commit

If at this point you do a git reset, here’s how the type of reset (“soft”, “hard”, or the default, which is “mixed”) affects things:

$ git checkout mywork
            # --hard resets to this point
...edit edit edit...
            # --mixed (default) resets to this point
$ git add ...
            # --soft resets to this point
$ git commit

Also note, as gitster says, that git commit --amend makes the git reset --soft mostly redundant.