12. kartzontech
• Git Workflow is different
• Be ready to UN-LEARN
• Un-sophisticated UI clients
• Git CLI is cool and friendly. Use It!
• Git is not a server by itself.
• That’s unlike SVN, CVS, etc.
• But, that’s okay - really!
17. kartzontech
• 40-digit alphanumeric “object name”
• look like 70a114563ec375ff9ecf335fdc4ac27027a454b4
• SHA 1 hash of the object contents
• SHA 1 is a cryptographic hash function
• SHA 1 helps determine object uniqueness
SHA - The Foundation
18. kartzontech
• Blob
• file contents
• chunk of binary data
• doesn’t have any attributes
• .. not even file name
• renaming file doesn’t change this object
• its location independent (in directory tree)
• Want to see blob contents?
git show <sha_of_blob>
4 Object Types - The Blob
19. kartzontech
• Tree
• represents contents of a (sub-)directory
• has pointers to blobs and other (sub-)trees
• Want to see Tree contents?
git [show | ls-tree] <sha_of_tree>
4 Object Types - The Tree
20. kartzontech
• Commit
• links physical state of tree w/
• a description of how we got there (link to parent) and
• why (the commit message)
• Want to not just see but examine your Commit?
git log --pretty=raw
git show -s --pretty=raw <sha_of_commit>
4 Object Types - The Commit
24. kartzontech
• Copy EXISTING repo.
$ git clone <url_of_remote_repo>
• Create NEW repo
$ mkdir <new_proj_name>
$ cd <new_proj_name>
$ git init
• Check current state of your repo
$ git status
Kick-startYour Work
25. kartzontech
Persist to your local repo
$ git add [filename | foldername]
$ git commit -m <my_message>
Modify And Commit
26. kartzontech
• Rollback change BEFORE staging
$ git checkout <file_name>
• Rollback change AFTER staging
$ git reset HEAD <file_name>
$ git checkout <file_name>
Modify And Rollback
28. kartzontech
• Delete a file in repo
$ rm <file_name>
$ git rm <file_name>
$ git commit -m <commit_message>
Remove it from my repo!
29. kartzontech
Hasty Dev, I am..
Instead of adding log files to .gitignore,
I hurriedly added them to index (staging area).
$ git add -A .
$ git status
# On branch my_pet_feature
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
new file: errors.log
#
new file: out.log
Now.. what do I do?
QUIZ
(Shit that happens..)
30. kartzontech
Don’t you worry!
Simply “remove the files from index”
$ git rm --cached *.log
$ git status
# On branch my_pet_feature
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
# errors.log
# out.log
32. kartzontech
I confess!
I not only added but did a local commit as well
$ git add -A .
$ git commit -m “bad commit”
QUIZ
(Shittier things happen as well)
33. kartzontech
No worries!..You are SAFE!!!
$ git reset --soft HEAD^
$ git status
# On branch my_pet_feature
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
modified: abc.txt
#
new file: errors.log
#
new file: out.log
$ git rm --cached *.log
$ git status
# On branch my_pet_feature
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
# errors.log
# out.log
Alternatively:
$ git reset HEAD^
$ git status
# On branch my_pet_feature
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
# errors.log
# out.log
37. kartzontech
The Routine
1. Show me latest commits
git log
2. Show me the last 2 commits
git log -2
3. Show me the patch introduced with each commit
git log -p
4. Show me just the commit messages
git log --pretty=oneline
git log --oneline
38. kartzontech
The Fun Stuff
1. Show me the commits for last 2 weeks
git log --since=2.weeks
2. Show me the commits before 3 months
git log --before=3.months
3. Show me the commits authored by ‘karthik’ only
git log --author=karthik
4. Show me just the commit where the commiter is ‘karthik’
git log --committer=karthik
39. kartzontech
QUIZ: Do Try It At Home :)
1. Show me commits made during the first two days of this week
git log _______________________
2. Show me the commits made since the last half hour
git log _______________________
3. Show me the commits authored by ‘karthik’ for the last 10 days
git log _______________________
4. Show me just the commits where the commiter is ‘karthik’ and author is ‘ganesh’
git log _______________________
5. I’ve a commit (with sha a1fix) to fix a high priority bug in Production. I need to merge
these changes in other developmental branches as well. What is the efficient way to do
it?
6. I’ve made some really bad local commits in my feature branch. Can I undo it?
41. kartzontech
Resources and Recommendations
1. Pro Git by Scott Chacon
2. http://git-scm.com/book (FREE online version of Pro Git)
3. http://git-scm.com/docs
4. http://try.github.io (Got 15 minutes and want to learn Git?)
5. Git in the Trenches by Peter Savage (http://cbx33.github.io/gitt/)
6. https://git.wiki.kernel.org/index.php/GitSvnComparsion
7. http://blog.jessitron.com/
42. kartzontech
I would really appreciate your feedback...
Please do feel free to drop a note at SpeakerRate
(http://speakerrate.com/talks/25891-git-for-fun-and-productivity)