I was in need of finding the commit that added a specific file in my project and “I got lucky” on Google:
Say we need the commit that introduced foo.js in the project, the command would be:
$ git log --diff-filter=A -- foo.js
And a super nice alias would be:
$ git config --global alias.whatadded 'log --diff-filter=A --'
and to use it:
$ git whatadded filename
There are several ways of displaying the differences between your git branches. The simplest ones being a little fuzzy and, if the diff is big enough, not very helpful. But thre are some tweaks we can make. The one I’ve been using mostly in the past weeks is:
Well, like always, when I see too big a command like this, I create an alias for it.
Anyway, this will print the current layout of all branches of your project, including the remote ones.
It produces a cool graph layout with the commit title only, and it’s a very useful way to understand where things are in your project. However, if it’s really a big project, it might be too overwhelming.
I created some new branches with new commits and got a little more elaborated tree, like this:
For the graph above, I created a new branch “bug883” from “develop” and “sample_branch” from “master”. None of them was pushed remotely, as we can tell by the output.
Well, give it a try and share what you think.
UPDATE: Many other ways of getting the diffs are discussed in this Stack Overflow post.
Creating git aliases is as easy as it is useful to speed your production time in development. The hard way — not so hard, actually — is as simple as adding a string in your
/home/$USER/.gitconfig file. Like so:
co = checkout
st = status
unstage = reset HEAD --
wc = whatchanged
Well, if you do not have any aliases configured yet, create an
[alias] block there and start appending your aliases.
However, the easiest way is to issue a command line in your terminal, and the alias will be added for you and will be ready to be used. E.g.:
git config --global alias.st status
git config --global alias.wc whatchanged
Keep adding them as you wish.
To use them, just issue
git <your-alias> [args]
from the command line.
Go ahead and share your most used aliases in the comments.
Thanks for reading.