Git - tips and tricks

552 views

Published on

Talk given at Yelster Digital GmbH workshop in 2011.

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
552
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Git - tips and tricks

  1. 1. git Tips & Tricks Wallace Reis | wreis Tuesday, October 08, 2013
  2. 2. Best practices? Tuesday, October 08, 2013
  3. 3. https://trac.dev.123people.com/trac/wiki/git/workflow Tuesday, October 08, 2013
  4. 4. Tuesday, October 08, 2013
  5. 5. [alias] st = status ci = commit -v addi = add --interactive br = checkout -b co = checkout pick = cherry-pick -s praise = blame -w up = !git stash && git pull -- rebase && git submodule update && git stash apply who = shortlog -se -- Tuesday, October 08, 2013
  6. 6. Find out wtf something was done that way? Tuesday, October 08, 2013
  7. 7. $ git blame -s Module.pm Tuesday, October 08, 2013
  8. 8. 892dc8d8 1) package Module; 892dc8d8 2) ... 892dc8d8 3) ... Tuesday, October 08, 2013
  9. 9. $ git show 892dc8d8 Tuesday, October 08, 2013
  10. 10. Delete remote branches? Tuesday, October 08, 2013
  11. 11. $ git push origin :branch_name Tuesday, October 08, 2013
  12. 12. Revert uncommitted changes? Tuesday, October 08, 2013
  13. 13. $ git checkout -- <filename> or $ git reset --hard HEAD Tuesday, October 08, 2013
  14. 14. Revert a commit? Tuesday, October 08, 2013
  15. 15. $ git revert 892dc8d8 Tuesday, October 08, 2013
  16. 16. And remove untracked files? Tuesday, October 08, 2013
  17. 17. $ git clean -n -d # dry run then $ git clean -d -f # “f” may not be required Tuesday, October 08, 2013
  18. 18. How to mangle the last commit done? Tuesday, October 08, 2013
  19. 19. $ git commit --amend Tuesday, October 08, 2013
  20. 20. How about reverting it? Tuesday, October 08, 2013
  21. 21. $ git revert HEAD Tuesday, October 08, 2013
  22. 22. Which changes will a branch bring in the next merge? Tuesday, October 08, 2013
  23. 23. $ git log --stat master..integration or $ git cherry -v master integration Tuesday, October 08, 2013
  24. 24. How about changes since last deployment? Tuesday, October 08, 2013
  25. 25. $ git log --stat release-1.53..HEAD or $ git cherry -v release-1.53 HEAD Tuesday, October 08, 2013
  26. 26. How about changes since last pull? Tuesday, October 08, 2013
  27. 27. $ git fetch origin $ git log --stat master..origin/ master or $ git cherry -v master origin/ master Tuesday, October 08, 2013
  28. 28. Which branches are not merged yet... Tuesday, October 08, 2013
  29. 29. ...into integration branch? $ git branch --no-merged integration Tuesday, October 08, 2013
  30. 30. Would like to see a file some revisions ago? Tuesday, October 08, 2013
  31. 31. $ git show HEAD~3:Module.pm or $ git show 892dc8d8:Module.pm or $ git show branch_name:Module.pm Tuesday, October 08, 2013
  32. 32. Reorder, squash, delete, or edit commits Tuesday, October 08, 2013
  33. 33. $ git rebase -i HEAD~4 Tuesday, October 08, 2013
  34. 34. pick dec6340 update plaxo and live tabs pick 5e1adaf Update plaxo and live icons pick 7f0473a Fix flickr icon pick 0b04eda Added Vimeo tracking. # Rebase b7722d5..0b04eda onto b7722d5 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x <cmd>, exec <cmd> = Run a shell command <cmd>, and stop if it fails # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. Tuesday, October 08, 2013
  35. 35. r dec6340 update plaxo and live tabs f 5e1adaf Update plaxo and live icons pick 0b04eda Added Vimeo tracking. e 7f0473a Fix flickr icon # Rebase b7722d5..0b04eda onto b7722d5 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x <cmd>, exec <cmd> = Run a shell command <cmd>, and stop if it fails # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. Tuesday, October 08, 2013
  36. 36. Recover lost commits Tuesday, October 08, 2013
  37. 37. $ git reflog Tuesday, October 08, 2013
  38. 38. cb462ba HEAD@{5}: checkout: moving from 154544202d4ff890a89ca4df30286d5c7edf0b39 to master 1545442 HEAD@{6}: commit: Add foo to shared_components e3456b3 HEAD@{7}: checkout: moving from cb462ba81c606f3e75d797712d9b49deddb442b0 to e3456b3d337084136b5c95ddb7268d68bf428a8e cb462ba HEAD@{8}: checkout: moving from e3456b3d337084136b5c95ddb7268d68bf428a8e to cb462ba81c606f3e75d797712d9b49deddb442b0 e3456b3 HEAD@{9}: checkout: moving from master to e3456b3d337084136b5c95ddb7268d68bf428a8e Tuesday, October 08, 2013
  39. 39. merge or format-patch + am Tuesday, October 08, 2013
  40. 40. Thank you! Discussion? Tuesday, October 08, 2013

×