Skip to content
Snippets Groups Projects
Commit ef4d7217 authored by Vermaat's avatar Vermaat
Browse files

Merge branch 'updates_bow' into 'master'

Updates bow

Slight delay because yesterday some things took more time than I predicted..

But I think the tips presentation is ready now :). I added the git-prompt.sh file (which comes with a git install) to the repository just to be sure we have a backup in case the file is not available in the laptops.

Other than that, I skipped the autocrlf / safecrlf config since it seems more complicated for first-time git users. Instead, I added some slides about `git add --patch` for selective commits of line changes, which I think is more useful (and easier to grasp).

Anyway, comments are welcomed.
parents d0537ebd c97df55d
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
\title{Git Basics} \title{Git Basics}
\providecommand{\myConference}{Git course} \providecommand{\myConference}{Git course}
\providecommand{\myDate}{Monday, October 14, 2013} \providecommand{\myDate}{Monday, June 23, 2014}
\author{Jeroen F. J. Laros} \author{Jeroen F. J. Laros}
\providecommand{\myGroup}{Leiden Genome Technology Center} \providecommand{\myGroup}{Leiden Genome Technology Center}
\providecommand{\myDepartment}{Department of Human Genetics} \providecommand{\myDepartment}{Department of Human Genetics}
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
\bigskip \bigskip
\begin{lstlisting}[language=none, caption=Make a new repository.] \begin{lstlisting}[language=none, caption=Make a new repository.]
$ cd ~/projects
$ git init $ git init
Initialized empty Git repository in <path>/.git/ Initialized empty Git repository in <path>/.git/
\end{lstlisting} \end{lstlisting}
...@@ -186,6 +187,43 @@ ...@@ -186,6 +187,43 @@
\end{lstlisting} \end{lstlisting}
\end{frame} \end{frame}
\begin{frame}[fragile]
\frametitle{Undoing changes.}
Keep in mind that ``\bt{git reset}'' by default sets a staged file back to unstaged.
\begin{lstlisting}[language=none, caption=Unstage a file.]
$ git reset README
$ git status
# Changes not staged for commit:
# modified: README
\end{lstlisting}
\bigskip
\pause
To discard all changes in an unstaged file, you can use ``\bt{git checkout}''
\begin{lstlisting}[language=none, caption=Discarding changes.]
$ git checkout -- .
$ git status
nothing to commit, working directory clean
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undoing changes.}
For now, let's commit our change and move on.
\bigskip
\begin{lstlisting}[language=none, caption=Adding a new version of a file.]
$ echo Second version. > README
$ git commit
$ git status
nothing to commit, working directory clean
\end{lstlisting}
\bigskip
\end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Viewing the history.} \frametitle{Viewing the history.}
...@@ -193,8 +231,6 @@ ...@@ -193,8 +231,6 @@
\bigskip \bigskip
\begin{lstlisting}[language=none, caption=The log of our project.] \begin{lstlisting}[language=none, caption=The log of our project.]
$ git add README
$ git commit
$ git log $ git log
commit cc61ee7cd72590f3bebcc9e1ff3e9435c7f7dd28 commit cc61ee7cd72590f3bebcc9e1ff3e9435c7f7dd28
Author: J.F.J. Laros <j.f.j.laros@lumc.nl> Author: J.F.J. Laros <j.f.j.laros@lumc.nl>
...@@ -228,7 +264,7 @@ ...@@ -228,7 +264,7 @@
\bigskip \bigskip
\pause \pause
You can also use an unique prefix of this hash, usually six characters is You can also use a unique prefix of this hash, usually six characters is
enough. enough.
\end{frame} \end{frame}
...@@ -341,6 +377,8 @@ ...@@ -341,6 +377,8 @@
Zuotian Tatum Zuotian Tatum
Wibowo Arindrarto
\end{center} \end{center}
\vfill \vfill
......
../presentation/Makefile
\ No newline at end of file
../presentation/beamerthemelumc.sty
\ No newline at end of file
../presentation/gen2phen_logo.eps
\ No newline at end of file
# bash/zsh git prompt support
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Distributed under the GNU General Public License, version 2.0.
#
# This script allows you to see repository status in your prompt.
#
# To enable:
#
# 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
# 2) Add the following line to your .bashrc/.zshrc:
# source ~/.git-prompt.sh
# 3a) Change your PS1 to call __git_ps1 as
# command-substitution:
# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
# ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
# the optional argument will be used as format string.
# 3b) Alternatively, for a slightly faster prompt, __git_ps1 can
# be used for PROMPT_COMMAND in Bash or for precmd() in Zsh
# with two parameters, <pre> and <post>, which are strings
# you would put in $PS1 before and after the status string
# generated by the git-prompt machinery. e.g.
# Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
# will show username, at-sign, host, colon, cwd, then
# various status string, followed by dollar and SP, as
# your prompt.
# ZSH: precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
# will show username, pipe, then various status string,
# followed by colon, cwd, dollar and SP, as your prompt.
# Optionally, you can supply a third argument with a printf
# format string to finetune the output of the branch status
#
# The repository status will be displayed only if you are currently in a
# git repository. The %s token is the placeholder for the shown status.
#
# The prompt status always includes the current branch name.
#
# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
# unstaged (*) and staged (+) changes will be shown next to the branch
# name. You can configure this per-repository with the
# bash.showDirtyState variable, which defaults to true once
# GIT_PS1_SHOWDIRTYSTATE is enabled.
#
# You can also see if currently something is stashed, by setting
# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
# then a '$' will be shown next to the branch name.
#
# If you would like to see if there're untracked files, then you can set
# GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked
# files, then a '%' will be shown next to the branch name. You can
# configure this per-repository with the bash.showUntrackedFiles
# variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is
# enabled.
#
# If you would like to see the difference between HEAD and its upstream,
# set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates you are behind, ">"
# indicates you are ahead, "<>" indicates you have diverged and "="
# indicates that there is no difference. You can further control
# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list
# of values:
#
# verbose show number of commits ahead/behind (+/-) upstream
# name if verbose, then also show the upstream abbrev name
# legacy don't use the '--count' option available in recent
# versions of git-rev-list
# git always compare HEAD to @{upstream}
# svn always compare HEAD to your SVN upstream
#
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
# find one, or @{upstream} otherwise. Once you have set
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
# setting the bash.showUpstream config variable.
#
# If you would like to see more information about the identity of
# commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
# to one of these values:
#
# contains relative to newer annotated tag (v1.6.3.2~35)
# branch relative to newer tag or branch (master~4)
# describe relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
# default exactly matching tag
#
# If you would like a colored hint about the current dirty state, set
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
# the colored output of "git status -sb" and are available only when
# using __git_ps1 for PROMPT_COMMAND or precmd.
# check whether printf supports -v
__git_printf_supports_v=
printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
# stores the divergence from upstream in $p
# used by GIT_PS1_SHOWUPSTREAM
__git_ps1_show_upstream ()
{
local key value
local svn_remote svn_url_pattern count n
local upstream=git legacy="" verbose="" name=""
svn_remote=()
# get some config options from git-config
local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
while read -r key value; do
case "$key" in
bash.showupstream)
GIT_PS1_SHOWUPSTREAM="$value"
if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
p=""
return
fi
;;
svn-remote.*.url)
svn_remote[$((${#svn_remote[@]} + 1))]="$value"
svn_url_pattern="$svn_url_pattern\\|$value"
upstream=svn+git # default upstream is SVN if available, else git
;;
esac
done <<< "$output"
# parse configuration values
for option in ${GIT_PS1_SHOWUPSTREAM}; do
case "$option" in
git|svn) upstream="$option" ;;
verbose) verbose=1 ;;
legacy) legacy=1 ;;
name) name=1 ;;
esac
done
# Find our upstream
case "$upstream" in
git) upstream="@{upstream}" ;;
svn*)
# get the upstream from the "git-svn-id: ..." in a commit message
# (git-svn uses essentially the same procedure internally)
local -a svn_upstream
svn_upstream=($(git log --first-parent -1 \
--grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
if [[ 0 -ne ${#svn_upstream[@]} ]]; then
svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]}
svn_upstream=${svn_upstream%@*}
local n_stop="${#svn_remote[@]}"
for ((n=1; n <= n_stop; n++)); do
svn_upstream=${svn_upstream#${svn_remote[$n]}}
done
if [[ -z "$svn_upstream" ]]; then
# default branch name for checkouts with no layout:
upstream=${GIT_SVN_ID:-git-svn}
else
upstream=${svn_upstream#/}
fi
elif [[ "svn+git" = "$upstream" ]]; then
upstream="@{upstream}"
fi
;;
esac
# Find how many commits we are ahead/behind our upstream
if [[ -z "$legacy" ]]; then
count="$(git rev-list --count --left-right \
"$upstream"...HEAD 2>/dev/null)"
else
# produce equivalent output to --count for older versions of git
local commits
if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
then
local commit behind=0 ahead=0
for commit in $commits
do
case "$commit" in
"<"*) ((behind++)) ;;
*) ((ahead++)) ;;
esac
done
count="$behind $ahead"
else
count=""
fi
fi
# calculate the result
if [[ -z "$verbose" ]]; then
case "$count" in
"") # no upstream
p="" ;;
"0 0") # equal to upstream
p="=" ;;
"0 "*) # ahead of upstream
p=">" ;;
*" 0") # behind upstream
p="<" ;;
*) # diverged from upstream
p="<>" ;;
esac
else
case "$count" in
"") # no upstream
p="" ;;
"0 0") # equal to upstream
p=" u=" ;;
"0 "*) # ahead of upstream
p=" u+${count#0 }" ;;
*" 0") # behind upstream
p=" u-${count% 0}" ;;
*) # diverged from upstream
p=" u+${count#* }-${count% *}" ;;
esac
if [[ -n "$count" && -n "$name" ]]; then
__git_ps1_upstream_name=$(git rev-parse \
--abbrev-ref "$upstream" 2>/dev/null)
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
p="$p \${__git_ps1_upstream_name}"
else
p="$p ${__git_ps1_upstream_name}"
# not needed anymore; keep user's
# environment clean
unset __git_ps1_upstream_name
fi
fi
fi
}
# Helper function that is meant to be called from __git_ps1. It
# injects color codes into the appropriate gitstring variables used
# to build a gitstring.
__git_ps1_colorize_gitstring ()
{
if [[ -n ${ZSH_VERSION-} ]]; then
local c_red='%F{red}'
local c_green='%F{green}'
local c_lblue='%F{blue}'
local c_clear='%f'
else
# Using \[ and \] around colors is necessary to prevent
# issues with command line editing/browsing/completion!
local c_red='\[\e[31m\]'
local c_green='\[\e[32m\]'
local c_lblue='\[\e[1;34m\]'
local c_clear='\[\e[0m\]'
fi
local bad_color=$c_red
local ok_color=$c_green
local flags_color="$c_lblue"
local branch_color=""
if [ $detached = no ]; then
branch_color="$ok_color"
else
branch_color="$bad_color"
fi
c="$branch_color$c"
z="$c_clear$z"
if [ "$w" = "*" ]; then
w="$bad_color$w"
fi
if [ -n "$i" ]; then
i="$ok_color$i"
fi
if [ -n "$s" ]; then
s="$flags_color$s"
fi
if [ -n "$u" ]; then
u="$bad_color$u"
fi
r="$c_clear$r"
}
__git_eread ()
{
f="$1"
shift
test -r "$f" && read "$@" <"$f"
}
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
# when called from PS1 using command substitution
# in this mode it prints text to add to bash PS1 prompt (includes branch name)
#
# __git_ps1 requires 2 or 3 arguments when called from PROMPT_COMMAND (pc)
# in that case it _sets_ PS1. The arguments are parts of a PS1 string.
# when two arguments are given, the first is prepended and the second appended
# to the state string when assigned to PS1.
# The optional third parameter will be used as printf format string to further
# customize the output of the git-status string.
# In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
__git_ps1 ()
{
local pcmode=no
local detached=no
local ps1pc_start='\u@\h:\w '
local ps1pc_end='\$ '
local printf_format=' (%s)'
case "$#" in
2|3) pcmode=yes
ps1pc_start="$1"
ps1pc_end="$2"
printf_format="${3:-$printf_format}"
;;
0|1) printf_format="${1:-$printf_format}"
;;
*) return
;;
esac
# ps1_expanded: This variable is set to 'yes' if the shell
# subjects the value of PS1 to parameter expansion:
#
# * bash does unless the promptvars option is disabled
# * zsh does not unless the PROMPT_SUBST option is set
# * POSIX shells always do
#
# If the shell would expand the contents of PS1 when drawing
# the prompt, a raw ref name must not be included in PS1.
# This protects the user from arbitrary code execution via
# specially crafted ref names. For example, a ref named
# 'refs/heads/$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' might cause the
# shell to execute 'sudo rm -rf /' when the prompt is drawn.
#
# Instead, the ref name should be placed in a separate global
# variable (in the __git_ps1_* namespace to avoid colliding
# with the user's environment) and that variable should be
# referenced from PS1. For example:
#
# __git_ps1_foo=$(do_something_to_get_ref_name)
# PS1="...stuff...\${__git_ps1_foo}...stuff..."
#
# If the shell does not expand the contents of PS1, the raw
# ref name must be included in PS1.
#
# The value of this variable is only relevant when in pcmode.
#
# Assume that the shell follows the POSIX specification and
# expands PS1 unless determined otherwise. (This is more
# likely to be correct if the user has a non-bash, non-zsh
# shell and safer than the alternative if the assumption is
# incorrect.)
#
local ps1_expanded=yes
[ -z "$ZSH_VERSION" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
[ -z "$BASH_VERSION" ] || shopt -q promptvars || ps1_expanded=no
local repo_info rev_parse_exit_code
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
--is-bare-repository --is-inside-work-tree \
--short HEAD 2>/dev/null)"
rev_parse_exit_code="$?"
if [ -z "$repo_info" ]; then
if [ $pcmode = yes ]; then
#In PC mode PS1 always needs to be set
PS1="$ps1pc_start$ps1pc_end"
fi
return
fi
local short_sha
if [ "$rev_parse_exit_code" = "0" ]; then
short_sha="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
fi
local inside_worktree="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
local bare_repo="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
local inside_gitdir="${repo_info##*$'\n'}"
local g="${repo_info%$'\n'*}"
local r=""
local b=""
local step=""
local total=""
if [ -d "$g/rebase-merge" ]; then
__git_eread "$g/rebase-merge/head-name" b
__git_eread "$g/rebase-merge/msgnum" step
__git_eread "$g/rebase-merge/end" total
if [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i"
else
r="|REBASE-m"
fi
else
if [ -d "$g/rebase-apply" ]; then
__git_eread "$g/rebase-apply/next" step
__git_eread "$g/rebase-apply/last" total
if [ -f "$g/rebase-apply/rebasing" ]; then
__git_eread "$g/rebase-apply/head-name" b
r="|REBASE"
elif [ -f "$g/rebase-apply/applying" ]; then
r="|AM"
else
r="|AM/REBASE"
fi
elif [ -f "$g/MERGE_HEAD" ]; then
r="|MERGING"
elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
r="|CHERRY-PICKING"
elif [ -f "$g/REVERT_HEAD" ]; then
r="|REVERTING"
elif [ -f "$g/BISECT_LOG" ]; then
r="|BISECTING"
fi
if [ -n "$b" ]; then
:
elif [ -h "$g/HEAD" ]; then
# symlink symbolic ref
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
local head=""
if ! __git_eread "$g/HEAD" head; then
if [ $pcmode = yes ]; then
PS1="$ps1pc_start$ps1pc_end"
fi
return
fi
# is it a symbolic ref?
b="${head#ref: }"
if [ "$head" = "$b" ]; then
detached=yes
b="$(
case "${GIT_PS1_DESCRIBE_STYLE-}" in
(contains)
git describe --contains HEAD ;;
(branch)
git describe --contains --all HEAD ;;
(describe)
git describe HEAD ;;
(* | default)
git describe --tags --exact-match HEAD ;;
esac 2>/dev/null)" ||
b="$short_sha..."
b="($b)"
fi
fi
fi
if [ -n "$step" ] && [ -n "$total" ]; then
r="$r $step/$total"
fi
local w=""
local i=""
local s=""
local u=""
local c=""
local p=""
if [ "true" = "$inside_gitdir" ]; then
if [ "true" = "$bare_repo" ]; then
c="BARE:"
else
b="GIT_DIR!"
fi
elif [ "true" = "$inside_worktree" ]; then
if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
[ "$(git config --bool bash.showDirtyState)" != "false" ]
then
git diff --no-ext-diff --quiet --exit-code || w="*"
if [ -n "$short_sha" ]; then
git diff-index --cached --quiet HEAD -- || i="+"
else
i="#"
fi
fi
if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
[ -r "$g/refs/stash" ]; then
s="$"
fi
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
[ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null
then
u="%${ZSH_VERSION+%}"
fi
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
__git_ps1_show_upstream
fi
fi
local z="${GIT_PS1_STATESEPARATOR-" "}"
# NO color option unless in PROMPT_COMMAND mode
if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
__git_ps1_colorize_gitstring
fi
b=${b##refs/heads/}
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
__git_ps1_branch_name=$b
b="\${__git_ps1_branch_name}"
fi
local f="$w$i$s$u"
local gitstring="$c$b${f:+$z$f}$r$p"
if [ $pcmode = yes ]; then
if [ "${__git_printf_supports_v-}" != yes ]; then
gitstring=$(printf -- "$printf_format" "$gitstring")
else
printf -v gitstring -- "$printf_format" "$gitstring"
fi
PS1="$ps1pc_start$gitstring$ps1pc_end"
else
printf -- "$printf_format" "$gitstring"
fi
}
../presentation/lgtc_logo.eps
\ No newline at end of file
../presentation/lumc_logo.eps
\ No newline at end of file
../presentation/lumc_logo_small.eps
\ No newline at end of file
../presentation/nbic_logo.eps
\ No newline at end of file
../presentation/ngi_logo.eps
\ No newline at end of file
../presentation/nwo_logo_en.eps
\ No newline at end of file
../pics/
\ No newline at end of file
\documentclass[slidestop]{beamer}
\title{Git Tips and Tricks}
\providecommand{\myConference}{Git course}
\providecommand{\myDate}{Monday, June 23, 2014}
\author{Wibowo Arindrarto}
\providecommand{\myGroup}{Sequencing Analysis Support Core}
\providecommand{\myDepartment}{}
\providecommand{\myCenter}{}
\providecommand{\lastCenterLogo}{
\raisebox{-0.1cm}{
\includegraphics[height=1cm]{lgtc_logo}
%\includegraphics[height=0.7cm]{ngi_logo}
}
}
\providecommand{\lastRightLogo}{
%\includegraphics[height=0.7cm]{nbic_logo}
%\includegraphics[height=0.8cm]{nwo_logo_en}
%\hspace{1.5cm}\includegraphics[height=0.7cm]{gen2phen_logo}
}
\usetheme{lumc}
\begin{document}
% This disables the \pause command, handy in the editing phase.
%\renewcommand{\pause}{}
% Make the title page.
\bodytemplate
% First page of the presentation.
\section{Introduction}
\begin{frame}[fragile]
\frametitle{}
We have only been playing with some of what git offers. In reality,
you can do much more with it. It also allows for a wide array of
customizations.
\bigskip
We will look into some of these customizations now.
\end{frame}
\section{Custom Prompt}
\begin{frame}[fragile]
\frametitle{}
Checking which branch you are working on and its status is
a routine task.
\bigskip
\pause
``\bt{git status}'' is useful, but quickly feels repetitive.
\begin{lstlisting}[language=none, caption=Routine git checking]
$ git branch
* master
$ git status
nothing to commit, working directory clean
\end{lstlisting}
\bigskip
\pause
Solution: use a custom shell prompt that displays git status.
\begin{lstlisting}[language=none, caption=Git checking with custom prompt]
(master) $ git st
nothing to commit, working directory clean
\end{lstlisting}
\bigskip
\end{frame}
\section{Custom Prompt}
\begin{frame}[fragile]
\frametitle{}
The git-approved way to do this is to use the ``\bt{\_\_git\_ps1}''
shell function defined in the ``\bt{git-prompt.sh}'' file.
\bigskip
\pause
The location of this file depends on your OS and git version. For now,
you can download a copy of this file from our GitLab.
\bigskip
\pause
Then, in you ``\bt{.bashrc}'' file, add ``\bt{\_\_git\_ps1}'' to the
``\bt{PS1}'' variable, and source your ``\bt{.bashrc}'' again.
\bigskip
\end{frame}
\section{Useful git commands}
\begin{frame}[fragile]
\frametitle{git blame}
Git tracks each line of each file in its repository.
\bigskip
\pause
You can view who committed the line change, the commit hash,
and the commit time using ``\bt{git blame}''
\begin{lstlisting}[language=none, caption=git blame command]
$ git blame README
a4394d28 (bow 2014-06 ...) Second version.
\end{lstlisting}
\bigskip
\end{frame}
\section{Useful git commands}
\begin{frame}[fragile]
\frametitle{git tag}
Sometimes, it is practical to refer to a commit with a name
instead of a hash.
\bigskip
\pause
Official releases, for example, are better referred as v1.0
than a76a0fx.
\bigskip
\pause
This can be done using ``\bt{git tag}''.
\end{frame}
\section{Useful git commands}
\begin{frame}[fragile]
\frametitle{git tag}
\begin{lstlisting}[language=none, caption=Adding a tag]
$ git tag "v0.0.1"
$ git show v0.0.1
commit a4394d28e6ba30be19318ee74f732a103b8ffdf2
Author: bow <bow@bow.web.id>
Date: Sat Jun 21 13:47:03 2014 +0200
Second commit
diff --git a/README b/README
index efe6f7c..4fe6328 100644
--- a/README
+++ b/README
@@ -1 +1 @@
-First version.
+Second version.
\end{lstlisting}
\bigskip
\end{frame}
\section{Useful git commands}
\begin{frame}[fragile]
\frametitle{git tag}
What we did previously is to add what is called a lightweight tag.
Lightweight tags are essentially commit aliases.
\bigskip
\pause
There is another type of tag, called the annotated tag.
\bigskip
\pause
Annotated tags contain more information: tagger identity,
tagging message, tagging date, and can be verified with GPG.
\bigskip
\end{frame}
\section{Useful git commands}
\begin{frame}[fragile]
\frametitle{git tag}
\begin{lstlisting}[language=none, caption=Adding an annotated tag]
$ git tag -a "v0.0.1" -m "Alpha version"
tag v0.1.0
Tagger: bow <bow@bow.web.id>
Date: Sat Jun 21 15:11:53 2014 +0200
Alpha version
commit a4394d28e6ba30be19318ee74f732a103b8ffdf2
Author: bow <bow@bow.web.id>
Date: Sat Jun 21 13:47:03 2014 +0200
Second commit
diff --git a/README b/README
index efe6f7c..4fe6328 100644
--- a/README
+++ b/README
@@ -1 +1 @@
-First version.
+Second version.
\end{lstlisting}
\bigskip
\end{frame}
\section{Useful git options}
\begin{frame}[fragile]
\frametitle{git diff -w}
Sometimes, you want to hide whitespace differences when using
``\bt{git diff}''.
\bigskip
\pause
This can be done via ``\bt{git diff -w}''
\begin{lstlisting}[language=none, caption=git diff without whitespace]
$ git diff -w
\end{lstlisting}
\bigskip
\pause
Note that while this aids visualization of the diff, git will still
commit the whitespace change.
\bigskip
\end{frame}
\section{Useful git options}
\begin{frame}[fragile]
\frametitle{git commit --amend}
Git gives you total control over your history, which means you can also
change them.
\bigskip
\pause
This practice is potentially dangerous and should not be part of your
regular workflow. This is especially true for public commits.
\bigskip
\pause
Still, there are times when changing that one last commit makes more
sense than doing a ``\bt{git revert}''
\bigskip
\pause
``\bt{git commit --amend}'' allows you to do that: changing your last
commit.
\bigskip
\end{frame}
\section{Useful git options}
\begin{frame}[fragile]
\frametitle{git commit --amend}
When run on a clean branch (no uncommitted changes),
``\bt{git commit --amend}'' allows you to change your last commit message.
\bigskip
\pause
You can also use the command to meld current staged changes to your last
committed change.
\begin{lstlisting}[language=none, caption=git blame command]
$ git status
Changes to be committed:
modified: README
$ git commit --amend -m "Update README"
[master b60437d] Second update
1 file changed, 1 insertion(+), 1 deletion(-)
\end{lstlisting}
\bigskip
\end{frame}
\section{Useful git options}
\begin{frame}[fragile]
\frametitle{git add --patch}
Often, uncommited change overextends. You start with the intention of
fixing bug A, but in the middle found that you can implement feature B
and feature C while also squashing bug D.
\bigskip
\pause
At the end of the day, only ``\bt{git commit -am "Updates"}'' is done
and the whole change is saved in a single comit.
\bigskip
\pause
This defeats the purpose of tracking your changes in commits. Commits
ideally represents a single, functional update, which you can understand
later on.
\bigskip
\end{frame}
\section{Useful git options}
\begin{frame}[fragile]
\frametitle{git add --patch}
You can, infact, commit the line changes selectively. This helps
split a mesh of changes into separate commits.
\begin{lstlisting}[language=none, caption=git add --patch]
$ git add --patch
\end{lstlisting}
\bigskip
\end{frame}
\section{Main Configuration File}
\begin{frame}[fragile]
\frametitle{Viewing}
In Linux, git uses the ``\bt{~/.gitconfig}'' file as its main
configuration file.
\bigskip
\pause
To see the current configuration values, use ``\bt{git config --list}''.
\begin{lstlisting}[language=none, caption=Git config values]
$ git config --list
user.name=bow
user.email=bow@bow.web.id
color.ui=auto
\end{lstlisting}
\bigskip
\end{frame}
\section{Main Configuration File}
\begin{frame}[fragile]
\frametitle{Modifying}
To edit the file directly, open ``\bt{~/.gitconfig}'' in a text editor
and save your changes.
\begin{lstlisting}[language=none, caption=Modifying the config file]
$ vim ~/.gitconfig
\end{lstlisting}
\bigskip
\pause
You can also use the ``\bt{git config --global}'' to set the values via the shell.
\begin{lstlisting}[language=none, caption=Modifying via the shell]
$ git config --global user.name "Linus Torvalds"
\end{lstlisting}
\bigskip
\end{frame}
\section{Main Configuration File}
\begin{frame}[fragile]
\frametitle{Modifying: global ignore}
We will look at two examples now: setting a global ignore file and
setting aliases.
\bigskip
\pause
In addition to setting a directory-specific ``\bt{.gitignore}'' file,
you can also set a global ignore file.
\bigskip
\pause
You can name this file anything. The convention is to use
``\bt{.gitignore\_global}'' and place the file in your home directory.
\bigskip
\end{frame}
\section{Main Configuration File}
\begin{frame}[fragile]
\frametitle{}
The global ignore file has the same format as the per-directory
``\bt{.gitignore}'' file, only visible to all git repositories.
\bigskip
\pause
\begin{lstlisting}[language=none, caption=Setting the global ignore file]
$ echo "*.out" > ~/.gitignore_global
$ echo "testing.txt" > ~/.gitignore_global
$ git config --global core.excludesfile \
"~/.gitignore_global"
\end{lstlisting}
\bigskip
\pause
\begin{lstlisting}[language=none, caption=Ignoring via the global file]
$ echo "Is this the real life?" > this.out
$ touch testing.txt
$ git status
nothing to commit, working directory clean
\end{lstlisting}
\bigskip
\end{frame}
\section{Main Configuration File}
\begin{frame}[fragile]
\frametitle{Aliases}
You can alias simple commands.
\begin{lstlisting}[language=none, caption=Simple alias]
$ git config --global alias.st status
$ git st
nothing to commit, working directory clean
\end{lstlisting}
\bigskip
\pause
Or more complex commands.
\begin{lstlisting}[language=none, caption=Complex alias]
$ git config --global alias.qlog \
"log --pretty=oneline"
$ git qlog
a4394d28e... Second commit
80eafd7e6... First commit
\end{lstlisting}
\bigskip
\end{frame}
\section{GitLab and GitHub}
\begin{frame}[fragile]
\frametitle{Demo time!}
\end{frame}
\section{Questions?}
\lastpagetemplate
\begin{fframe}
\begin{center}
Acknowledgements:
\bigskip
\bigskip
Martijn Vermaat
Jeroen F. J. Laros
\end{center}
\vfill
\permfoot{http://git-scm.com/book}
\end{fframe}
\end{document}
../presentation/ul_logo.eps
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment