Having used Git for so long, it is safe to say that you know nothing about Git. My daily use is limited to commit, add, merge, etc. This is not my inquisitive personality. No, we have to study it. Where do we start? All Git projects have such a folder. How about starting with git? Well, let’s see what’s in this folder.
The.git folder contains all the information about your git repository.
- Submit the history
- Temporary content
- The current branch
- Remote branch path
- , etc.
Well, let’s see what we have:
It’s all here. Ok, let’s go through the files one by one.
First, let’s talk about my current operation on this test project.
; Md git add readme.md git commit -m'add readme'; Modify file Submissionecho test > readme.md
git add readme.md
git commit -m 'change readme'; Git checkout -b master_testCopy the code
Only two commits were made to keep the.git folder in its original state for easy viewing.
COMMIT_EDITMSG
This file holds information about the last COMMIT. If you don’t know what to do with it, you can just git it.
HEAD
Save the branch currently in use.
In addition, you can modify the git checkout file directly to accomplish the purpose of the git checkout command.
Also, from the contents of this file, it can be inferred that the refs folder is used to hold branch information, but this will be recorded in the small book for later.
config
Needless to say, it is used to save configuration information.
Git config –local user.name ‘git_test’
If, as expected, the remote address is also saved here, add git remote add Origin http://test.com/aa/bb
description
Without further ado, above, the document description is used to fill in the description of the project.
hooks
The hook functions that hold the project add their own execution logic before and after the various operations. I haven’t used this before. There are sample files in the folder, just delete the suffix. Sample to use.
- Pre-commit: triggered before the commit. Can be used to inspect code
- Prepare-commit-msg: indicates before the commit and after the message is added.
- Commit-msg: called at commit time. Message can be modified or the commit can be cancelled
- Post-commit: invoked after the commit
- Post-update: triggered after push
- Pre-receive: called before the actual push when pushing
- Pre-push: triggered before push
- Pre-merge-commit: triggered before the merge
- Pre-rebase: triggered before rebase
And so on, specific information can be viewed in the official website documents
As you can see, this folder is used to automate the management of the workflow.
index
Used to save the contents of the local staging area. Binary file, cannot be viewed directly. To view the current staging area contents, run the git ls-files –stage command.
info
There is currently only one file in the path: exclude. This file is used to ignore certain files in Git. Unlike.gitignore, this file is not committed. That is, to ignore files that you only use locally.
logs
Used to record all operation records. Take a look at the contents of my local files.
The HEAD file records all operations, while the refs folder records operations in each branch.
Git reset –hard {id} git reset –hard {id}
objects
This file holds all git history changes, leaving the structure of the file for future study. I won’t go into that for now.
Git GC can be used to reduce file size.
refs
Save local branches and labels. The content of the file is simple, just a COMMIT ID.
Git/Packed -refs This file contains all the information under refs, and the files under Refs will be emptied.
Other documents
FATCH_HEAD
Used to store remote branch information
ORIG_HEAD
Back up the contents of the “HEAD” file when performing operations such as merge, reset, and rebase.
sourcetreeconfig
When using Sourcetree to manage a project, it is used to save the configuration information in sourcetree.
After going through the contents in the.git folder, I found the basic location for saving the contents, but I still don’t understand the binary file for saving the contents.
After a while, I found some things that helped me, such as the local ignore, which added.gitignore to the path and ignored the.gitignore file itself. Git /info/exclude