I want to read from the file where git stores commit history to store each commit information in my project's DB and display all histories in my project view
There's no single file you can interrogate to get the commit history. There are plenty of good explanations of git's object model (e.g. git for computer scientists, Pro Git, the git community book), but it might be useful to have a quick explanation here:
There are various types of objects in git, most importantly:
Each of these is identified by a hash of its contents, and this hash is known as the object name - these are the 40 digit hex strings you've probably seen in the course of using git. Each object is stored in the .git/objects/
directory, either as a loose object (one per file) or as one of many objects stored efficiently in a pack file. The file .git/HEAD
represents the version that your repository is currently at, and usually contains a reference to a particular branch, represented by a file under .git/refs/heads
or a reference stored in pack file. (HEAD
may also point directly to a particular commit's object name.) One of these files representing a branch, such as .git/refs/heads/master
, just contains an object name.
In order to traverse the history back from this branch tip, git will find the object named in that file in the object database, and recursively follow the pointers to its parents.
However, for the use case you describe (i.e. traversing the history to export it), I would strongly suggest that you do one of the following: