Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Monday, February 3, 2020

Git project branch and directory info

To get the Git top level, or root, of the repo:

git rev-parse --show-toplevel

Get the current current branch name:

git rev-parse --abbrev-ref HEAD

Get the current working directory relative to project root:

echo "${PWD##$(git rev-parse --show-toplevel)}"

Get the current working directory relative to project root and the branch name in one line:

echo "${PWD##$(git rev-parse --show-toplevel)} [$(git rev-parse --abbrev-ref HEAD)]"

Tuesday, March 17, 2015

Print the current tag OR commit in git

Here's the command to print the tag name of the current commit, or just the commit if there is no tag. It's useful for a script that builds or exports something and you always want to have some version reference..
# prints tag name or short revision
git name-rev --tags --name-only --no-undefined --always $(git rev-parse HEAD)

Friday, November 14, 2014

git lsd – For when you don't want to use gitk --all

If all you want is a quick look at your commit history with all the branches nicely laid out with their merges shown with pretty colored lines... Try this instead of one of the gui viewers:
git log --graph --boundary '--format=%C(yellow)%h%Creset%C(bold cyan)%d%Creset %s %C(dim normal)(%ar)%Creset' --all
This will output something like this (depending on your terminal color settings):
* 4b22a90 (HEAD, master) erases chip before programming (2 days ago)
*   ee107af Merge branch 'sysclk' (2 days ago)
|\  
| * e9df6f6 removes clk config to use defaults (2 days ago)
| * 66a1ea3 fixes clkout pin timing (2 days ago)
| * bcdda54 enables PLL @ 16MHz (internal 2MHz x 8) (2 days ago)
| * cd22bab enables the 32KHz rc for system clock (2 days ago)
| * cee8efd enables the internal 32MHz rc for sysclk (2 days ago)
| * aa10b4d enables 2MHz internal rc osc for sysclk (2 days ago)
| * 80cbade re-defines F_CPU (2 days ago)
|/  
*   0644c9d Merge branch 'diagnostics' (3 days ago)
|\  
| * b9e155d adds SYSCLK/10000 on pin A0 (3 days ago)
| * 57807ab adds blinky led (3 days ago)
|/  
* 5cfc996 basic skeleton (3 days ago)
Of course you can mess with the format and colors, but this is how I like it. Once you have it set the way you like it, alias it for later use!
git config --global alias.lsd "log --graph --boundary '--format=%C(yellow)%h%Creset%C(bold cyan)%d%Creset %s %C(dim normal)(%ar)%Creset' --all"
Now you can just type git lsd and have a quick overview of your commits.