A talk by torstein @ escenic
Let’s start with a wee tour of Git
$ mkdir git-for-p4ers
$ cd git-for-p4ers
$ git init
$ echo 'O Captain! my Captain! our fearful trip is done,' \
> poem.txt
$ git add poem.txt
$ git commit
This roughly corresponds to our trunk
today.
$ git checkout -b develop
$ echo "The ship has weather’d every rack, " \
"the prize we sought is won," \
>> poem.txt
$ git status
$ git diff
$ git commit -a -m "The ship is not doing so well."
$ git checkout master
$ git checkout -b release/5.7
$ echo "The port is near, the bells I hear, " \
"the people all exulting," \
>> poem.txt
$ git commit poem.txt -m "The port is near."
$ git checkout master
$ git checkout -b release/5.8
$ echo "While follow eyes the steady keel, " \
"the vessel grim and daring;" \
>> poem.txt
$ git commit poem.txt -m "Steady keel."
$ git checkout release/5.7
$ git checkout -b hotfix/memory-leak-cs
$ echo 'But O heart! heart! heart!' >> poem.txt
$ git commit -m "Fixed memory leak in CS using hearts" poem.txt
Again, the convention is that bug fix branches are prefixed hotfix/
.
$ git checkout release/5.7
$ git merge hotfix/memory-leak-cs
$ git checkout release/5.7
$ git log # take note of the SHA
$ git checkout release/5.8
$ git cherry-pick <sha>
A good practice is to create a new feature branch for each JIRA issue.
$ git checkout develop
$ git checkout -b feature/VF-100-npe-in-ece
$ echo "O the bleeding drops of red," >> poem.txt
$ git commit -m "Another drop" poem.txt
$ echo "Where on the deck my Captain lies," >> poem.txt
$ git commit -m "Captain lies" poem.txt
$ echo "Fallen cold and dead." >> poem.txt
$ git commit -m "Cold and dead" poem.txt
Squash and re-arrange commits, improve the commit messages:
$ git rebase -i
pick 100a6ad Another drop
squash e4dffae Captain lies
squash 27300b1 Cold and dead
$ git push
$ git pull
$ git checkout release/5.7
$ git tag 5.7.1
$ git push --tags
This will probably take some time to sink in:
There is no server.
$ git remote -v
git commit
as often as you want locally.git push
your changes for the world to see.$ git commit pom.xml -m "Removed unused dependency."
$ git push
$ git checkout -b feature/VF-2134-xml-support
$ git rebase
If you want to avoid trouble, don’t use git rebase
except for:
$ git rebase --interactive # or -i
There are no limits to how much you can mess up when using git rebase
😊
$ git annotate <file>
Show me all commits mentioning UTF-8 somewhere in their multiline commit messages:
$ git log --grep UTF-8
Show me all commits mentioning UTF-8 authored by lisa that contain a code diff that uses HashMap
:
$ git log --patch --grep UTF-8 --author lisa | grep HashMap
$ git log --patch
$ git status
$ git diff
Or how to p4 integrate
a change if you will.
$ git checkout develop
$ git log # copy the commit SHA
$ git checkout release/5.7
$ git cherry-pick 4bba83875b0d04f3a3340f15f9864c46152c6c6b
$ git log --stat --decorate @{u}...
$ git diff hotfix/VF-200-memory-leak-cs ...
├── develop
│ ├── feature/VF-100-cs-memory-leak
│ └── feature/VF-200-search-for-author
└── release/5.7
│ ├── hotfix/apidoc-bug-javaws
│ └── hotfix/npe-in-ws
└── release/5.8
master
holds the latest release.
$ git p4 clone //depot/escenic/engine/trunk@all engine
$ git remote add stash \
https://username@our.stash.com:7999/escenic/engine.git
$ git push stash develop
Add (at least) the following to your ~/.gitconfig
:
[user]
name = Walt Whitman
email = walt@withman.com
[branch]
autosetuprebase = always
[push]
default = current
[core]
excludesfile = ~/.gitignore
If you’re on Windows, also add:
[core]
# especially useful on Windows where the executable bit is
# constantly set making git list the file as modified.
fileMode = false
git
will launch whetere is in the EDITOR
variable whenever you’re composing a commit message, are running interactive rebase
, add
or the like:
$ echo EDITOR=vim >> $HOME/.bashrc
$ source $HOME/.bashrc
This works equally well in Windows/Cygwin, Mac OS X or Linux.
There’s pretty good auto completion for git in BASH
$ echo source /usr/share/bash-completion/completions/git \
>> $HOME/.bashrc
Using alias
es makes your git foo much faster:
alias gb='git branch'
alias gc='git checkout'
alias gca='git commit --amend'
alias gd='git diff'
alias gl='git log'
alias glp='git log -p'
alias gpr='git pull --rebase'
alias gri='git rebase -i'
alias gs='git status'
Plenty of fancy BASH and ZSH git
prompts going around:
git
prompt that I use, see get_git_status() and PS1echo comments > torstein @ escenic