Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git from scratch

Git from scratch

A Git introduction from scratch to some advanced topics like Rebasing

Xabier Larrakoetxea

December 18, 2013
Tweet

More Decks by Xabier Larrakoetxea

Other Decks in Programming

Transcript

  1. Subversion CVS Team Foundation ... VCS Server Repo User 1

    Project User 2 Project User N Project Version Control System
  2. Git Mercurial Bazaar ... DVCS Server Repo User 1 Repo

    User 2 Repo User N Repo Distributed Version Control System
  3. Git uses snapshots not diffs File 1 Version 1 File

    2 File 3 File 4 File 1 Version 2 File 2 File 3 File 4 Version 3 File 2 File 3 File 4 Version 4 File 2 File 3 File 1 File 1 File 4
  4. Working directory Staging area Git directory (repo) Remote Git directory

    (repo) Stage files Checkout Project Commit Push changes
  5. Working directory Staging area Git directory (repo) Remote Git directory

    (repo) Stage files Checkout Project Commit Push changes WTF is this?!
  6. Git File types Commit Tree Author Comitter Tree Blob Blob

    Blob Blob Print(“Hello world”) Blob package main import( “fmt” ) Blob README HI!
  7. Ignoring files https://github.com/github/gitignore # Byte-compiled / optimized / DLL files

    __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging bin/ build/ develop-eggs/ dist/ eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging bin/ build/ develop-eggs/ dist/ eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .gitignore
  8. Repo status $ git status # On branch master #

    Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: queueworkers/settings.py # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: queueworkers/logging.conf # modified: queueworkers/utils/logs.py # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # queueworkers/test
  9. Repo Diffs diff --git a/queueworkers/utils/messageimporter.py b/queueworkers/utils/messageimporter.py index 8c5e904..fe57a72 100644 ---

    a/queueworkers/utils/messageimporter.py +++ b/queueworkers/utils/messageimporter.py @@ -12,8 +12,8 @@ def exec_publisher(publisher, body, channel, method): try: publisher.connect() publisher.publish(body) - if settings.SEND_ACK: - channel.basic_ack(delivery_tag=method.delivery_tag) + #if settings.SEND_ACK: + # channel.basic_ack(delivery_tag=method.delivery_tag) except Exception as e: logger.error("Exception: " + str(e)) raise $ git diff
  10. commit -a shortcut Working directory Staging area Repository $ Git

    add $ Git commit Working directory Staging area Repository $ Git commit -a
  11. Repo log * 3b3eac4 (HEAD, branch2) Edited README3 in branch2

    | * 77c48e7 (master) Merge branch 'branch2' | |\ | |/ |/| * | 3699398 Modified README 3 in branch2 | * 3cc6283 Modified README 3 in master branch |/ * 736c954 Modified README 3 * 56dedf6 Modified README 1 and 2 * c2f5d57 Initial commit $ git log --graph --decorate --oneline --all http://garmoncheg.blogspot.com.es/2012/06/pretty-git-log.html
  12. Repo remotes $ git remote add mirror https://mymirror.com/go-copy.git mirror https://mymirror.com/go-copy.git

    (fetch) mirror https://mymirror.com/go-copy.git (push) origin [email protected]:slok/go-copy.git (fetch) origin [email protected]:slok/go-copy.git (push) $ git remote -v origin [email protected]:slok/go-copy.git (fetch) origin [email protected]:slok/go-copy.git (push) $ git remote -v
  13. Workflow Working directory Repository Commit n Working directory Repository Commit

    n+1 Working directory Repository Commit n+2 Working directory Remote repo Push
  14. Git Revert 5f201b3 Updated readme 58e5b57 Implemented creation of dirs

    in the file service $ git log -n2 --oneline d19f591 Revert "Updated readme" 5f201b3 Updated readme 58e5b57 Implemented creation of dirs in the file service $ git log -n3 --oneline [master d19f591] Revert "Updated readme" 1 file changed, 1 insertion(+), 1 deletion(-) $ git revert 5f201b3
  15. Checkout vs Reset C1 C2 C3 C5 master HEAD C1

    C2 C3 C5 master HEAD $ git checkout master~2 $ git reset HEAD~2
  16. Branches * devel master remotes/origin/HEAD -> origin/master remotes/origin/master $ git

    branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch -a Switched to a new branch 'devel' $ git checkout -b devel
  17. Fast forward merge C1 C2 C3 C5 master dev C1

    C2 C3 C5 master dev Updating 817e279..48cdf3a Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) $ git merge dev
  18. Conflicts $ git add ./file4.txt Auto-merging file4.txt CONFLICT (content): Merge

    conflict in file4.txt Automatic merge failed; fix conflicts and then commit the result. $ git merge dev <<<<<<< HEAD Oh! I'm the only developer here ======= No... You are not alone and this will conflict >>>>>>> dev $ cat ./file4.txt [master 1e90c43] Merge branch 'dev' $ git commit
  19. $ git tag -a v1.0 -m "Version 1.0" -a v0.1

    f539ca3 -m "Version 0.1" -d f539ca3
  20. Remote tags Counting objects: 2, done. Delta compression using up

    to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 311 bytes, done. Total 2 (delta 0), reused 0 (delta 0) To [email protected]:slok/basic-git.git * [new tag] v0.1 -> v0.1 * [new tag] v1.0 -> v1.0 $ git push --tags origin
  21. $ git stash Saved working directory and index state WIP

    on master: 34f7998 #31 Add implementation to mark notifications as read or unread HEAD is now at 34f7998 #31 Add implementation to mark notifications as read or unread $ git stash # On branch master # Your branch is ahead of 'origin/master' by 3 commits. # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: dwarf/notifications/urls.py # modified: dwarf/notifications/views.py # no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (4cdbd16404fc6e8e378a669df2f168afa71ff1a5) $ git stash pop
  22. Rebase step 1 * 17d7264 (master) added notifications index template

    | * d9d7f36 (HEAD, testing) add more urls for notifications | * b2b673a add urls for notification |/ $ git log --graph -n 3 --oneline --all --decorate First, rewinding head to replay your work on top of it... Applying: add urls for notification Applying: add more urls for notifications $ git rebase master * 893eaef (HEAD, testing) add more urls for notifications * bd886fb add urls for notification * 17d7264 (master) added notifications index template $ git log --graph -n 3 --oneline --all --decorate
  23. Rebase step 1 * 17d7264 (master) added notifications index template

    | * d9d7f36 (HEAD, testing) add more urls for notifications | * b2b673a add urls for notification |/ $ git log --graph -n 3 --oneline --all --decorate First, rewinding head to replay your work on top of it... Applying: add urls for notification Applying: add more urls for notifications $ git rebase master * 893eaef (HEAD, testing) add more urls for notifications * bd886fb add urls for notification * 17d7264 (master) added notifications index template $ git log --graph -n 3 --oneline --all --decorate WTF?!
  24. Rebase step 2 * 893eaef (HEAD, testing, master) add more

    urls for notifications * bd886fb add urls for notification * 17d7264 added notifications index template $ git log --graph -n 3 --oneline --all --decorate Switched to branch 'master' Your branch is ahead of 'origin/master' by 4 commits. $ git checkout master Updating 17d7264..893eaef Fast-forward dwarf/notifications/views.py | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) $ git merge testing http://www.youtube.com/watch?v=cSf8cO0WB4o
  25. Icons: Entypo Typography: Google web fonts OS Logos: http://commons.wikimedia.org Github:

    https://github.com Google docs: https://docs.google.com Git: http://git-scm.com Progit: http://git-scm.com/book