fbbleg
Last Updated: February 25, 2016
·
2.862K
· alyssa
Thumb alyssa pohahau

useful git commands

merge multiple branches in one command. git will walk back the paths until all branches have the same parent

git merge branch1 branch2 branch3

create an annotated tag (unlike a reference tag, writes an object to .git/objects).

git tag -a <tag_name>

show most recent annotated tag that's reachable from a commit:

git describe <branch>

show most recent reference tag that's reachable from a commit:

git describe --tag <branch>

For my examples below, I'll be referring to commits from a repo of mine. For this repo, my initial commit's unique identifier (long hash) is: 2dd4049fec2546f8fc40e6218e971ff701edba39 and its short hash is: 2dd4

Find out what type an object (using its short hash) is:

git cat-file -t <short_hash>

<ignore>

$ git cat-file -t 2dd4
commit

Learn more about an object

git cat-file -p <short_hash>

<ignore>

$git cat-file -p 2dd4
tree 424426772a97a341b167da8836d00c9e64ea7b4d
author Alyssa Pohahau <my_email> 1343847754 -0700
committer Alyssa Pohahau <my_email> 1343847754 -0700

Initial commit

Take any kind of short hash and turn it into its unique identifier. (Note: rev-parse of an annotated tag gives you an object. Whereas, rev-parse of a reference tag gives you a pointer to an actual commit.)

git rev-parse <short_hash>

<ignore>

$ git rev-parse 2dd4
2dd4049fec2546f8fc40e6218e971ff701edba39

Find this commit's tree:

git rev-parse 'master^{tree}'

<ignore>

$ git rev-parse 'master^{tree}'
1a75bea90a06efa4ff1ec5a4091924ede90645bc
$ git cat-file -t 1a75
tree
$ git cat-file -p 1a75
100644 blob 73950f76e997d520f9361f1c6e47cbcb24911be0    README.md
100644 blob 9ca9c1b927d92208fb5fbcdbb488329348224fd2    color.rb
Say Thanks
Respond
Filed Under