Maintaining code for us developers has been quite smooth because we have a tool that can keep track of each version of the code that is being modified and kept in distributed manner.
Git is not only knowing pull, commit and push, there is lot more to it. if we understand git more we might handle our code versions a little more sensibly.
Play around with git
Inside git directory if you further look into .git directory(which is hidden usually), you'll see the commits and logs and other informations are being stored here. Incase for example you want to search your commits you previously made with certain message, you can simply hit the command
git log --grep="example search word"
where grep is global regular expression
git having three components, repository, staging and working directory where every changes we make in working directory and usually we push it to stage and then commit it to repository and each commit produces a hash code aka SHA value which is 40 unique hexadecimal characters and this SHA-1 is generated based on each and every changes you commit (e.g. text file, code, binary file). Hence, even adding a space will generate a different SHA-1 value. Interesting thing here to note is, once you commit a change, HEAD will point to recent commit and once you commit another change the HEAD will now point to latest change and this this will also include the previous change and if you visualize, it will be a sort of linked list.
[ Commit 1 ]------[ Commit 2 ]------[ Commit 3 ]
[ 48ae79b ]<------[ 56f9ca ]<------[ 9c78de ] <== HEAD
Snapshot-1 ------ Snapshot-2 ------ Snapshot-3
Now let's say you ant to compare two commits, one handy tool to find difference between two commits is
git diff b3c98a..c6ae4b
and if you want to commit all the changes skipping the staging part then you can use
git commit -a -m "some msg"
Resources
If you want to study git in detail, you can go through this url: https://www.toptal.com/git/the-advanced-git-guide
Top comments (0)