Reputation: 89
I have few doubt regarding git operation/workflow:
1.The Git SHA-1 is formed on each commit. I need to be clear regarding, which files are used for making that SHA?,
2.I am having Windows machine. I have installed Sourcetree(GitClient) alone, not git software. And I created a repo at Github.com(remote repository), and by these, I am achieving my workspace as versioning process. My workspace is at remote.
Please correct my thought if I am wrong -> "Without Installing Git server in our machine, we can achieve code versioning via Remote repository. And, if we need Local Repository, we should need Git server."
Please, someone, clarify my doubt's. Thank you :)
Upvotes: 0
Views: 378
Reputation: 56538
The SHA is a result of the parent object(s) hashes, the tree hash, the name and email of the author, the timestamp, the commit message text, and the files involved in the commit. (And the GPG signature, if one is present.)
That is why if you change the commit message, or rebase a commit, you end up with a new SHA.
The rest of the files in the repository are not directly involved in that SHA, but the SHA of the parent(s) of the commit are part of the calculation, so they are indirectly involved.
You can see the metadata involved by using cat-file
. Take a commit ID and do this:
$ git cat-file -p 3d911c37dc7cc6d50af9cbc66aa36084158308f5
tree 487660899e53bef8b15d3e1692172f689ed965c5
parent aa3b68973e845b7a900ab164603f154c8a1ba1c5
author Dan Lowe <[email protected]> 1483760015 -0500
committer Dan Lowe <[email protected]> 1483760015 -0500
Update line number settings in vim for 7.4+
Here we see the tree object, one parent, author & committer, and the commit message text. Not shown are the file objects attached, but they are there. In some cases a second parent is also present (e.g. a merge commit).
All git repositories are full repositories (except shallow clones). So if you make a new repository on your laptop, it is a full repository. You can add, remove, commit, rebase, all of those operations are completely local. The entire repository history is on your laptop. That is one reason git is so good at working offline.
However, most people that is not enough. They need to share code with other developers, or publish it for public consumption. This is the purpose of services like Github, Bitbucket, etc.
Those services are just another copy of the full repository, and you are synchronizing with it.
Here's something you can try. I'll use command line git instead of SourceTree.
## Make two repositories
mkdir a && cd a && git init
cd ..
mkdir b && cd b && git init --bare
## Add some content to 'a'
cd ../a
touch a.txt && git add . && git commit -m "New content"
## Set the other repository as your remote
git remote add origin ../b
## Let's push!
git push -u origin master
## Take a look at 'b' now...
cd ../b
git log
... and your commit from a is there. You just made a git server! Although not the most useful one really, because it's just on your disk. But if you put some SSH or https server in the middle... now you have Github, just without the fancy web interface part.
Upvotes: 4