Git - tips and tricks

Post on 07-May-2015

255 views 1 download

description

Talk given at Yelster Digital GmbH workshop in 2011.

Transcript of Git - tips and tricks

gitTips & Tricks

Wallace Reis | wreisTuesday, October 08, 2013

Best practices?

Tuesday, October 08, 2013

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

Tuesday, October 08, 2013

Tuesday, October 08, 2013

[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

Find out wtf something was done that way?

Tuesday, October 08, 2013

$ git blame -s Module.pm

Tuesday, October 08, 2013

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

Tuesday, October 08, 2013

$ git show 892dc8d8

Tuesday, October 08, 2013

Delete remote branches?

Tuesday, October 08, 2013

$ git push origin :branch_name

Tuesday, October 08, 2013

Revert uncommitted changes?

Tuesday, October 08, 2013

$ git checkout -- <filename>

or

$ git reset --hard HEAD

Tuesday, October 08, 2013

Revert a commit?

Tuesday, October 08, 2013

$ git revert 892dc8d8

Tuesday, October 08, 2013

And remove untracked files?

Tuesday, October 08, 2013

$ git clean -n -d # dry run

then

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

Tuesday, October 08, 2013

How to mangle the last commit done?

Tuesday, October 08, 2013

$ git commit --amend

Tuesday, October 08, 2013

How about reverting it?

Tuesday, October 08, 2013

$ git revert HEAD

Tuesday, October 08, 2013

Which changes will a branch bring in the next

merge?Tuesday, October 08, 2013

$ git log --stat master..integration

or

$ git cherry -v master integration

Tuesday, October 08, 2013

How about changes since last

deployment?

Tuesday, October 08, 2013

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

or

$ git cherry -v release-1.53 HEAD

Tuesday, October 08, 2013

How about changes since last pull?

Tuesday, October 08, 2013

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

or

$ git cherry -v master origin/master

Tuesday, October 08, 2013

Which branches are not merged yet...

Tuesday, October 08, 2013

...into integration branch?

$ git branch --no-merged integration

Tuesday, October 08, 2013

Would like to see a file some revisions ago?

Tuesday, October 08, 2013

$ git show HEAD~3:Module.pm

or

$ git show 892dc8d8:Module.pm

or

$ git show branch_name:Module.pm

Tuesday, October 08, 2013

Reorder, squash, delete, or edit

commits

Tuesday, October 08, 2013

$ git rebase -i HEAD~4

Tuesday, October 08, 2013

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

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

Recover lost commits

Tuesday, October 08, 2013

$ git reflog

Tuesday, October 08, 2013

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

merge or

format-patch + am

Tuesday, October 08, 2013

Thank you!Discussion?

Tuesday, October 08, 2013