To continue on the post of Persistent data structure and git, I've created this repo: https://github.com/mhewedy-playground/how-get-works
Looking into the objects database, here's the database objects exposed:
$ git log
commit d5ef93b09fe8d80fa903894a1bac93d3a67d55d3 (HEAD -> master)
Author: Muhammad Hewedy <mhewedy@gmail.com>
Date: Mon Mar 25 00:09:37 2019 +0300
commit 16dc45d02209a4bfcb26b066f18bf290507cf87f
Author: Muhammad Hewedy <mhewedy@gmail.com>
Date: Mon Mar 25 00:05:20 2019 +0300
---------------------------------------------------------------------
# first commit tree
$ git cat-file -p 16dc
tree 029ec860ecb064cf689695c176a5baafc910916a
author Muhammad Hewedy <mhewedy@gmail.com> 1553461520 +0300
committer Muhammad Hewedy <mhewedy@gmail.com> 1553461520 +0300
$ git cat-file -p 029e
040000 tree e9199b34206372b3d2b1e2c06b3ccfeaef6d8804 a
$ git cat-file -p e919
040000 tree b1d74266c8b55b9cd7796c056888b6edcc1d1a98 b
$ git cat-file -p b1d7
040000 tree 68aba62e560c0ebc3396e8ae9335232cd93a3f60 c
$ git cat-file -p 68ab
100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad hello.txt
---------------------------------------------------------------------
# second (HEAD/master) commit tree
$ git cat-file -p d5ef
tree 9d0986abb4d98c7b1a26e6a4efe2156981ebd583
parent 16dc45d02209a4bfcb26b066f18bf290507cf87f
author Muhammad Hewedy <mhewedy@gmail.com> 1553461777 +0300
committer Muhammad Hewedy <mhewedy@gmail.com> 1553461777 +0300
$ git cat-file -p 9d09
040000 tree 48bc9a2ae3efb7aef6095e4db249a5775b71d155 a
$ git cat-file -p 48bc
040000 tree 5899cb357c13a7e7fa8aacc9b73ad741877d5390 b
$ git cat-file -p 5899
040000 tree 68aba62e560c0ebc3396e8ae9335232cd93a3f60 c
100644 blob 345e6aef713208c8d50cdea23b85e6ad831f0449 test.txt
$ git cat-file -p 68ab
100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad hello.txt
Which is represented by the following diagram
Showing posts with label git. Show all posts
Showing posts with label git. Show all posts
24 March 2019
19 March 2019
Persistent data structure and git
From Wikipedia:
Consider git repo with the following log:
commit 5a19382be2d700129a0c0ca81340a8858075501b (HEAD -> master)
Author: Muhammad Hewedy <mhewedy@gmail.com>
Date: Tue Mar 19 23:35:34 2019 +0300
Modifing menu
commit 64dba215678c5a888c178990da7186f8ada939b0
Author: Muhammad Hewedy <mhewedy@gmail.com>
Date: Tue Mar 19 23:11:35 2019 +0300
First Commit
When catting the latest commit, and the one previous to it, they will share the same unchanged element.
lets check the latest commit:
$ git cat-file -p 5a19382be2d700129a0c0ca81340a8858075501b
tree 80c92c5fa5a179dec9d7f6f0b81b45dd7d32742d
parent 64dba215678c5a888c178990da7186f8ada939b0
author Muhammad Hewedy <mhewedy@gmail.com> 1553027734 +0300
committer Muhammad Hewedy <mhewedy@gmail.com> 1553027734 +0300
Modifing menu
$ git cat-file -p 80c92c5fa5a179dec9d7f6f0b81b45dd7d32742d
100644 blob 3e34d35b8b00e443866d4e9fcbb152a308497147 menu.txt
040000 tree 9cbe2293128382f7d60125add044260f8630012a recipes
Now let's check its parent commit (the first commit):
$ git cat-file -p 64dba215678c5a888c178990da7186f8ada939b0
tree 8ae44ec1b6ef7e4b66eb7be36fba1046081d7128
author Muhammad Hewedy <mhewedy@gmail.com> 1553026295 +0300
committer Muhammad Hewedy <mhewedy@gmail.com> 1553026295 +0300
First Commit
$ git cat-file -p 8ae44ec1b6ef7e4b66eb7be36fba1046081d7128
100644 blob 23991897e13e47ed0adb91a0082c31c82fe0cbe5 menu.txt
040000 tree 9cbe2293128382f7d60125add044260f8630012a recipes
The recipes tree has not been changed, and since both commits share it, however, the menu.txt file has been changed, so each commit links to its own version.
In the end, the head of the persistent data structure always refers to the latest version of it. with the ability to track every single change.
a persistent data structure is a data structure that always preserves the previous version of itself when it is modified. Such data structures are effectively immutable, as their operations do not update the structure in-place, but instead always yield a new updated structure.Git own objects database is a persistence data structure.
Consider git repo with the following log:
commit 5a19382be2d700129a0c0ca81340a8858075501b (HEAD -> master)
Author: Muhammad Hewedy <mhewedy@gmail.com>
Date: Tue Mar 19 23:35:34 2019 +0300
Modifing menu
commit 64dba215678c5a888c178990da7186f8ada939b0
Author: Muhammad Hewedy <mhewedy@gmail.com>
Date: Tue Mar 19 23:11:35 2019 +0300
First Commit
When catting the latest commit, and the one previous to it, they will share the same unchanged element.
lets check the latest commit:
$ git cat-file -p 5a19382be2d700129a0c0ca81340a8858075501b
tree 80c92c5fa5a179dec9d7f6f0b81b45dd7d32742d
parent 64dba215678c5a888c178990da7186f8ada939b0
author Muhammad Hewedy <mhewedy@gmail.com> 1553027734 +0300
committer Muhammad Hewedy <mhewedy@gmail.com> 1553027734 +0300
Modifing menu
$ git cat-file -p 80c92c5fa5a179dec9d7f6f0b81b45dd7d32742d
100644 blob 3e34d35b8b00e443866d4e9fcbb152a308497147 menu.txt
040000 tree 9cbe2293128382f7d60125add044260f8630012a recipes
Now let's check its parent commit (the first commit):
$ git cat-file -p 64dba215678c5a888c178990da7186f8ada939b0
tree 8ae44ec1b6ef7e4b66eb7be36fba1046081d7128
author Muhammad Hewedy <mhewedy@gmail.com> 1553026295 +0300
committer Muhammad Hewedy <mhewedy@gmail.com> 1553026295 +0300
First Commit
$ git cat-file -p 8ae44ec1b6ef7e4b66eb7be36fba1046081d7128
100644 blob 23991897e13e47ed0adb91a0082c31c82fe0cbe5 menu.txt
040000 tree 9cbe2293128382f7d60125add044260f8630012a recipes
The recipes tree has not been changed, and since both commits share it, however, the menu.txt file has been changed, so each commit links to its own version.
In the end, the head of the persistent data structure always refers to the latest version of it. with the ability to track every single change.
26 July 2016
Create Local git server
Actually git doesn't work with client-server concept, it is distributed source control, where any repo can act as a remote repo for others and in the same time a local repo.
But in your organization, you need to have a place where you have your code resides either for keep code save, or even to do automated deployment or for any other reason.
suppose you have 2 Linux machines, machine A and machine B. (machine A will act like a server, where machine B will be your development machine)
1. machine A have to have ssh server installed; Login to machine A with user say 'git':
2. go to a directory where you want to keep your code, or even you want to do the autodeployemnt from there
3. init the origin on the server
4. Your server is ready now, Now go to the client machine and create a folder where you will put your development source code:
5. create local git repo and point to the remote server we just created
6. test your installation:
7. that's it, you now can write code and push it to your server, you can add hocks on the server (for deployment) or install your a web server to show the code in fancy interface or support other activities like code-review, etc.
Have fun.
But in your organization, you need to have a place where you have your code resides either for keep code save, or even to do automated deployment or for any other reason.
suppose you have 2 Linux machines, machine A and machine B. (machine A will act like a server, where machine B will be your development machine)
1. machine A have to have ssh server installed; Login to machine A with user say 'git':
ssh git@machine_a
2. go to a directory where you want to keep your code, or even you want to do the autodeployemnt from there
sudo mkdir -p /repos/test-repo sudo chown -R git:git /repos/rest-repo
3. init the origin on the server
cd /repos/test-repo
git init --bare
4. Your server is ready now, Now go to the client machine and create a folder where you will put your development source code:
cd ~/my-test-repo-code
5. create local git repo and point to the remote server we just created
git init git remote add origin git@machine_a:/repos/test-repo
6. test your installation:
# we still in the client machine touch test-file.txt git add test-file.txt git commit -a -m 'init' git push remote origin
7. that's it, you now can write code and push it to your server, you can add hocks on the server (for deployment) or install your a web server to show the code in fancy interface or support other activities like code-review, etc.
Have fun.
Subscribe to:
Posts (Atom)