Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. ### What is Git? Describe the method Git uses to store files in a repository.
  2.  
  3. Git is a fully distributed Version Control System (VCS) that is efficient, robust, and simple to use.
  4.  
  5. If you are unfamiliar with Git or a VCS, think of the problems that can arise from a rudimentary system of copying a project directory and saving it under a new timestamp multiple times a day. Imagine a team working on this same directory and attempting to manually merge everyone's contributions.
  6.  
  7. Comparing changes between an old file and a new one is unreliable and attributing a change to a particular user is difficult. The solution is a version control system and there are a few types in use today.
  8.  
  9. Git mirrors a central repository, or the storage location of a project's history. If a server fails, projects are protected because there could be several clones on other local machines. This repository serves as the single point-of-entry for all changes. Multiple collaborators can copy the entire project, work independently, then integrate their changes back to the main repository with ease.
  10.  
  11. #### The Git Method
  12.  
  13. How does Git store files in a repository? It takes a snapshot of a project with the `git commit` command and stores it in a tree structure. Each commit is referenced by a SHA1 hash.
  14.  
  15. 18af1bb0ae95301e244f0c4d09c2f1d935d2ad2f
  16.  
  17. This snapshot is a comprehensive, unique record of what every file in the directory looked like at a moment in time and which user made the commit. By running `git add` and `git commit`, Git stores the commit, tree, and blob objects as separate files in the .git/objects directory.
  18. To demonstrate how Git stores files, create a simple repository.
  19.  
  20. $ mkdir my_repo
  21. $ cd my_repo
  22. $ git init
  23. Initialized empty Git repository in /Users/azure/my_repo/.git/
  24.  
  25. Next, stage the files and commit them.
  26.  
  27. $ echo "Hello World" > example.txt
  28. $ git add .
  29. $ git commit -m "Initial commit"
  30. [master (root-commit) 72757b0] Initial commit
  31. 1 file changed, 1 insertion(+)
  32. create mode 100644 example.txt
  33.  
  34. Now, view your project's files with the command `find .git/objects -type f`. The output will show three objects each named with a unique SHA1 checksum. By running the `git cat-file -t` command, you can inspect each object and determine whether it is a commit, tree, or blob. With the flag `-p`, you get a more detailed view.
  35.  
  36. $ find .git/objects -type f
  37. .git/objects/72/757b072e58bd2a48bcb19850ef755262e586ff
  38. .git/objects/91/dd72904e26baa26c934c5222714e460a43dc1b
  39. .git/objects/55/7db03de997c86a4a028e1ebd3a1ceb225be238
  40.  
  41. **Commit Object**
  42.  
  43. The commit object stores information about who saved the snapshot, when it was saved, what changes were made, and why they were made.
  44.  
  45. $ git cat-file -p 72757b072e58bd2a48bcb19850ef755262e586ff
  46. tree 91dd72904e26baa26c934c5222714e460a43dc1b
  47. author Azure <email@gmail.com> 1554763287 -0700
  48. committer Azure <email@gmail.com> 1554763287 -0700
  49.  
  50. Initial commit
  51.  
  52. **Tree Object**
  53.  
  54. Tree objects have their own SHA and can point to numerous blobs and trees that also have their own SHA numbers. The tree object in the example contains the contents of a directory. If a new directory is created, that will be listed as a subtree object beneath example.txt.
  55.  
  56. $ git cat-file -p 91dd72904e26baa26c934c5222714e460a43dc1b
  57. 100644 blob 557db03de997c86a4a028e1ebd3a1ceb225be238 example.txt
  58.  
  59. **Blob Object**
  60.  
  61. Blob stands for binary large object and it contains the content of a file.
  62.  
  63. $ git cat-file -p 557db03de997c86a4a028e1ebd3a1ceb225be238
  64. Hello World
  65.  
  66.  
  67. Git facilitates the collaboration between multiple users while preserving the history and keeping files up-to-date. Regardless of the project type, if version control is important to the work flow, Git will serve as a fantastic tool.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement