git graph parent child tabular format
git graph parent child tabular format
I am working on git and I am very much interested to see my changes into graph format . So I tried below command .
git log --oneline --graph --color --all --decorate
The above graph is not clear and tough to interpret .
Then i found another command , which has GUI. This was little more intuitive.
gitk --all
After doing some experiment , I thought of building d3 graph for more clear view . Something Like below . For that i need below data in table format .
| Commmit ID | Branch | Parent Id |
-----------------------------------
| 123ghj | Master | Null |
-----------------------------------
| 123hj | Master | 123ghj |
-----------------------------------
| 3456jk | Master |123ghj |
By keeping commit parent child , I can construct tree kind of structure.
Which I will use in d3.js to create graph like visualization . Can you help me to get this parent child structure using git command or group of command in python .
1 Answer
1
This should get you started. The "--pretty" format supplied is key:
git log --branches --tags --remotes --date-order --pretty="%H,%P,%D"
Notice how I'm using: --pretty="%H,%P,%D"
. (Note: you can use the lowercase %h and %p instead to see abbreviated commitId hashes).
--pretty="%H,%P,%D"
%H expands to show the commitId.
%P expands to show the parent commitIds.
%D expands to show the decorations (tags and branches).
But there are a few subtle problems with it:
%P will expand to all of %H's parent commits (separated by space), and so you'll need run the output through a 2nd script to better normalize that into a format suitable for D3.
%P might expand to 3 or more commits (very rare). These are called octopus merges!
%D expands to a comma separated list of decorations (branch and tag labels), and there's no limit on how many branches and tags a single commit might have.
Sample output (scroll to the right to see the branches and tags!):
d5cf1a13b9a8dad3f18eefcc676399a5c1b805de,8026da6db0fd7dbfe9c9eac1d1567827dd047e84 741bfe3932de28c20f401cc7e0447fffb2bea7d6,HEAD -> master, origin/master, origin/HEAD, HEAD
8026da6db0fd7dbfe9c9eac1d1567827dd047e84,624fe22914182b6ed05db3811d7c9fb9189273e6,
741bfe3932de28c20f401cc7e0447fffb2bea7d6,8b5d09a195f4d254d257d56fe7d10073fdf0cb23,origin/PHP-7.0, PHP-7.0
624fe22914182b6ed05db3811d7c9fb9189273e6,c1868b00cdeb7880a8372727da66aa30d94dc765 8b5d09a195f4d254d257d56fe7d10073fdf0cb23,
8b5d09a195f4d254d257d56fe7d10073fdf0cb23,99c44458da7f60af017f233a1e9d0b3f54efcdb4 8cd903ea685a6ef56aa77e95c00db8aac53a7c39,
8cd903ea685a6ef56aa77e95c00db8aac53a7c39,67f0770036f866f6f0dadc044cdc8f94a5b9f030,origin/PHP-5.6, PHP-5.6
99c44458da7f60af017f233a1e9d0b3f54efcdb4,f8506c062f8c4f72e12f20487bbb8c453602e5e7 4d4c6cf14ee855039f6dafcdcd14c32124963461,
c1868b00cdeb7880a8372727da66aa30d94dc765,ff8337b783dc8d5f44608afc87f51998f3223859 22475055c658e0efded795e8dea543406e6842a6,
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
this might help: github.com/esc/git-big-picture
– hiro protagonist
Jun 19 at 14:37