git
Tips & Tricks
Wallace Reis | wreis
Tuesday, 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 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
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
Recover lost commits
Tuesday, October 08, 2013
$ git reflog
Tuesday, October 08, 2013
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
merge
or
format-patch + am
Tuesday, October 08, 2013
Thank you!
Discussion?
Tuesday, October 08, 2013

Git - tips and tricks

  • 1.
    git Tips & Tricks WallaceReis | wreis Tuesday, October 08, 2013
  • 2.
  • 3.
  • 4.
  • 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.
    Find out wtfsomething was done that way? Tuesday, October 08, 2013
  • 7.
    $ git blame-s Module.pm Tuesday, October 08, 2013
  • 8.
    892dc8d8 1) packageModule; 892dc8d8 2) ... 892dc8d8 3) ... Tuesday, October 08, 2013
  • 9.
    $ git show892dc8d8 Tuesday, October 08, 2013
  • 10.
  • 11.
    $ git pushorigin :branch_name Tuesday, October 08, 2013
  • 12.
  • 13.
    $ git checkout-- <filename> or $ git reset --hard HEAD Tuesday, October 08, 2013
  • 14.
    Revert a commit? Tuesday,October 08, 2013
  • 15.
    $ git revert892dc8d8 Tuesday, October 08, 2013
  • 16.
  • 17.
    $ git clean-n -d # dry run then $ git clean -d -f # “f” may not be required Tuesday, October 08, 2013
  • 18.
    How to manglethe last commit done? Tuesday, October 08, 2013
  • 19.
    $ git commit--amend Tuesday, October 08, 2013
  • 20.
  • 21.
    $ git revertHEAD Tuesday, October 08, 2013
  • 22.
    Which changes willa branch bring in the next merge? Tuesday, October 08, 2013
  • 23.
    $ git log--stat master..integration or $ git cherry -v master integration Tuesday, October 08, 2013
  • 24.
    How about changes sincelast deployment? Tuesday, October 08, 2013
  • 25.
    $ git log--stat release-1.53..HEAD or $ git cherry -v release-1.53 HEAD Tuesday, October 08, 2013
  • 26.
    How about changes sincelast pull? Tuesday, October 08, 2013
  • 27.
    $ git fetchorigin $ git log --stat master..origin/ master or $ git cherry -v master origin/ master Tuesday, October 08, 2013
  • 28.
    Which branches are notmerged yet... Tuesday, October 08, 2013
  • 29.
    ...into integration branch? $ gitbranch --no-merged integration Tuesday, October 08, 2013
  • 30.
    Would like tosee a file some revisions ago? Tuesday, October 08, 2013
  • 31.
    $ git showHEAD~3:Module.pm or $ git show 892dc8d8:Module.pm or $ git show branch_name:Module.pm Tuesday, October 08, 2013
  • 32.
    Reorder, squash, delete, oredit commits Tuesday, October 08, 2013
  • 33.
    $ git rebase-i HEAD~4 Tuesday, October 08, 2013
  • 34.
    pick dec6340 updateplaxo 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.
    r dec6340 updateplaxo 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.
  • 37.
    $ git reflog Tuesday,October 08, 2013
  • 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.
  • 40.