Guest User

Untitled

a guest
Mar 1st, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. # How to make a commit with plumbing commands
  2.  
  3. ### 1. Setup Git repo
  4. - Make empty folder called `git-plumbing`. Git is not initialised!
  5. - Make `.git` directory where all the Git system will reside. Git is not initialised!
  6. - Git repository is a collection of object and a system for naming those objects (_refs_). Let's make `objects` and `refs` subfolders.
  7. - Let's make `.git/refs/heads` which keep track of branches. Git is not initialised!
  8. - The last missing piece to initialise a Gitrepo is a `HEAD` file with content:
  9. ```
  10. ref: refs/heads/master
  11. ```
  12.  
  13. ### 2. Hash data into a blob
  14. - Now we can create a hash of some data and generate a loose object (**blob**) out of it:
  15. ```bash
  16. $ echo "In Xanadu did Kubla Kahn" | git hash-object --stdin -w
  17. bf8febed0fafd7638ad2799f5925a9383039f58e
  18. ```
  19.  
  20. - I can see the actual content of the blob with:
  21. ```bash
  22. $ git cat-file -p bf8feb # -p is for pretty-print
  23. In Xanadu did Kubla Kahn
  24. ```
  25.  
  26. - I can find out what kind of Git object is with:
  27. ```bash
  28. $ git cat-file -t bf8feb # -t is for type
  29. blob
  30. ```
  31.  
  32. - I can find out the size of Git object with:
  33. ```bash
  34. $ git cat-file -s bf8feb # -s is for size in bytes
  35. 25
  36. ```
  37.  
  38. - Git status doesn't detect anything yet
  39.  
  40. ### 3. Growing a tree
  41. - Let's put the object in the staging area (index). 100644 is a magic number for permissions and I also have to specify to which file the content belongs to.
  42. ```bash
  43. $ git update-index --add --cacheinfo 100644 bf8febed0fafd7638ad2799f5925a9383039f58e coleridge.txt
  44. ```
  45. - We need to represent a directory structure. Git doesn't care about single files. We need a tree:
  46. ```bash
  47. $ git write-tree
  48. de31c78155075dcebcc969331b213d5ed81c6636
  49.  
  50. $ git cat-file -t de31c7
  51. tree
  52.  
  53. $ git cat-file -p de31c7 # printing content of tree
  54. 100644 blob bf8febed0fafd7638ad2799f5925a9383039f58e coleridge.txt
  55. ```
  56.  
  57. ### 4. The first commit
  58. - Git status doesn't care at all about my tree. I need to make a commit. The commit is the snapshot:
  59. ```bash
  60. $ git commit-tree de31c7 -m "Initial commit" f915575e03beebcef20778b99ae7aba5d00c0e9a # this is the commit hash
  61.  
  62. $ git cat-file -p f91557 # equivalent to git log --format=raw
  63. tree de31c78155075dcebcc969331b213d5ed81c6636
  64. author Simone Stefani <s.stefani95@gmail.com> 1518941735 +0100
  65. committer Simone Stefani <s.stefani95@gmail.com> 1518941735 +0100
  66.  
  67. Initial commit
  68. ```
  69.  
  70. - Git status is still not happy since the `HEAD` ref has not been adjusted. The ref folder doesn't have info about our commit. Let's add it:
  71. ```bash
  72. $ echo f915575e03beebcef20778b99ae7aba5d00c0e9a > .git/refs/heads/master
  73.  
  74. $ git log
  75. commit f915575e03beebcef20778b99ae7aba5d00c0e9a (HEAD -> master)
  76. Author: Simone Stefani <s.stefani95@gmail.com>
  77. Date: Sun Feb 18 09:15:35 2018 +0100
  78.  
  79. Initial commit
  80. ```
  81.  
  82. - Let's checkout the file. The `--` is a way for Git to apply the first part of the command only to some objects. We simply ask Git to take out the file `coleridge.txt` and put it into the working directory.
  83. ```bash
  84. $ git checkout -- coleridge.txt
  85. ```
  86. - Now status is happy and we can see the file in the folder
Add Comment
Please, Sign In to add comment