git - tips and tricks

40
git Tips & Tricks Wallace Reis | wreis Tuesday, October 08, 2013

Upload: wallace-reis

Post on 07-May-2015

251 views

Category:

Technology


1 download

DESCRIPTION

Talk given at Yelster Digital GmbH workshop in 2011.

TRANSCRIPT

Page 1: Git - tips and tricks

gitTips & Tricks

Wallace Reis | wreisTuesday, October 08, 2013

Page 2: Git - tips and tricks

Best practices?

Tuesday, October 08, 2013

Page 3: Git - tips and tricks

https://trac.dev.123people.com/trac/wiki/git/workflow

Tuesday, October 08, 2013

Page 4: Git - tips and tricks

Tuesday, October 08, 2013

Page 5: Git - tips and tricks

[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

Page 6: Git - tips and tricks

Find out wtf something was done that way?

Tuesday, October 08, 2013

Page 7: Git - tips and tricks

$ git blame -s Module.pm

Tuesday, October 08, 2013

Page 8: Git - tips and tricks

892dc8d8 1) package Module;892dc8d8 2) ...892dc8d8 3) ...

Tuesday, October 08, 2013

Page 9: Git - tips and tricks

$ git show 892dc8d8

Tuesday, October 08, 2013

Page 10: Git - tips and tricks

Delete remote branches?

Tuesday, October 08, 2013

Page 11: Git - tips and tricks

$ git push origin :branch_name

Tuesday, October 08, 2013

Page 12: Git - tips and tricks

Revert uncommitted changes?

Tuesday, October 08, 2013

Page 13: Git - tips and tricks

$ git checkout -- <filename>

or

$ git reset --hard HEAD

Tuesday, October 08, 2013

Page 14: Git - tips and tricks

Revert a commit?

Tuesday, October 08, 2013

Page 15: Git - tips and tricks

$ git revert 892dc8d8

Tuesday, October 08, 2013

Page 16: Git - tips and tricks

And remove untracked files?

Tuesday, October 08, 2013

Page 17: Git - tips and tricks

$ git clean -n -d # dry run

then

$ git clean -d -f # “f” may not be required

Tuesday, October 08, 2013

Page 18: Git - tips and tricks

How to mangle the last commit done?

Tuesday, October 08, 2013

Page 19: Git - tips and tricks

$ git commit --amend

Tuesday, October 08, 2013

Page 20: Git - tips and tricks

How about reverting it?

Tuesday, October 08, 2013

Page 21: Git - tips and tricks

$ git revert HEAD

Tuesday, October 08, 2013

Page 22: Git - tips and tricks

Which changes will a branch bring in the next

merge?Tuesday, October 08, 2013

Page 23: Git - tips and tricks

$ git log --stat master..integration

or

$ git cherry -v master integration

Tuesday, October 08, 2013

Page 24: Git - tips and tricks

How about changes since last

deployment?

Tuesday, October 08, 2013

Page 25: Git - tips and tricks

$ git log --stat release-1.53..HEAD

or

$ git cherry -v release-1.53 HEAD

Tuesday, October 08, 2013

Page 26: Git - tips and tricks

How about changes since last pull?

Tuesday, October 08, 2013

Page 27: Git - tips and tricks

$ git fetch origin$ git log --stat master..origin/master

or

$ git cherry -v master origin/master

Tuesday, October 08, 2013

Page 28: Git - tips and tricks

Which branches are not merged yet...

Tuesday, October 08, 2013

Page 29: Git - tips and tricks

...into integration branch?

$ git branch --no-merged integration

Tuesday, October 08, 2013

Page 30: Git - tips and tricks

Would like to see a file some revisions ago?

Tuesday, October 08, 2013

Page 31: Git - tips and tricks

$ git show HEAD~3:Module.pm

or

$ git show 892dc8d8:Module.pm

or

$ git show branch_name:Module.pm

Tuesday, October 08, 2013

Page 32: Git - tips and tricks

Reorder, squash, delete, or edit

commits

Tuesday, October 08, 2013

Page 33: Git - tips and tricks

$ git rebase -i HEAD~4

Tuesday, October 08, 2013

Page 34: Git - tips and tricks

pick dec6340 update plaxo and live tabspick 5e1adaf Update plaxo and live iconspick 7f0473a Fix flickr iconpick 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

Page 35: Git - tips and tricks

r dec6340 update plaxo and live tabsf 5e1adaf Update plaxo and live iconspick 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

Page 36: Git - tips and tricks

Recover lost commits

Tuesday, October 08, 2013

Page 37: Git - tips and tricks

$ git reflog

Tuesday, October 08, 2013

Page 38: Git - tips and tricks

cb462ba HEAD@{5}: checkout: moving from 154544202d4ff890a89ca4df30286d5c7edf0b39 to master1545442 HEAD@{6}: commit: Add foo to shared_componentse3456b3 HEAD@{7}: checkout: moving from cb462ba81c606f3e75d797712d9b49deddb442b0 to e3456b3d337084136b5c95ddb7268d68bf428a8ecb462ba HEAD@{8}: checkout: moving from e3456b3d337084136b5c95ddb7268d68bf428a8e to cb462ba81c606f3e75d797712d9b49deddb442b0e3456b3 HEAD@{9}: checkout: moving from master to e3456b3d337084136b5c95ddb7268d68bf428a8e

Tuesday, October 08, 2013

Page 39: Git - tips and tricks

merge or

format-patch + am

Tuesday, October 08, 2013

Page 40: Git - tips and tricks

Thank you!Discussion?

Tuesday, October 08, 2013