Git for-fun-and-productivity
-
Upload
karthik-sirasanagandla -
Category
Technology
-
view
1.862 -
download
0
description
Transcript of Git for-fun-and-productivity
kartzontech
For Fun And Productivity
Karthik Sirasanagandla
kartzontech
Why Git?
kartzontech
Speed
kartzontech
Space Compactness
kartzontech
Mozilla repo.
12 GB in SVN
Mozilla repo.
420 MB in Git
Distributed VCS
kartzontech
SVN Git
Resilience
kartzontech
Branching
kartzontech
Time, Space..
and fun!!..
Git Server
kartzontech
*Best place to look for to set up git server is http://git-scm.com/book/en/Git-on-the-Server
FREE Hosting Services
kartzontech
kartzontech
Any cons?And what's the way out?
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!
kartzontech
TheoryWhat You MUST Know!
kartzontech
Nearly everything is local
Browse logsCompare Diff
Local Commits
Local Branches
kartzontech
Snapshots Not Differences
SVN
Git
kartzontech
The
Git Object Model
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
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
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
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=rawgit show -s --pretty=raw <sha_of_commit>
4 Object Types - The Commit
kartzontech
Visualizing
Git Object Model
Need a Demo?
kartzontech
• Tag• A way to mark your commit as ‘special’
4 Object Types - Tag
Learn in your leisure..
kartzontech
PracticeWhat You SHOULD Do!
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-start Your Work
kartzontech
Persist to your local repo$ git add [filename | foldername]$ git commit -m <my_message>
Modify And Commit
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
kartzontech
View (Un-)Stanged Changes
kartzontech
• Delete a file in repo
$ rm <file_name>
$ git rm <file_name>
$ git commit -m <commit_message>
Remove it from my repo!
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..)
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
kartzontech
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)
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
kartzontech
kartzontech
git reset??
kartzontech
kartzontech
The Routine
1. Show me latest commitsgit log
2. Show me the last 2 commitsgit log -2
3. Show me the patch introduced with each commitgit log -p
4. Show me just the commit messagesgit log --pretty=onelinegit log --oneline
kartzontech
The Fun Stuff
1. Show me the commits for last 2 weeksgit log --since=2.weeks
2. Show me the commits before 3 monthsgit log --before=3.months
3. Show me the commits authored by ‘karthik’ onlygit log --author=karthik
4. Show me just the commit where the commiter is ‘karthik’git log --committer=karthik
kartzontech
QUIZ: Do Try It At Home :)
1. Show me commits made during the first two days of this weekgit log _______________________
2. Show me the commits made since the last half hourgit log _______________________
3. Show me the commits authored by ‘karthik’ for the last 10 daysgit 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?
Git Server
kartzontech
git init --bare new_repo_name.git
Client 1:git remote add origin <url>git push origin master
git clone <url>
Client 2:
kartzontech
Resources and Recommendations
1. Pro Git by Scott Chacon2. http://git-scm.com/book (FREE online version of Pro Git)3. http://git-scm.com/docs4. 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/GitSvnComparsion7. http://blog.jessitron.com/
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)