commit bd2103dd5aa03d7e4cfc5b4507d121c31c672485
parent 6413b552cd6c2f0bb6f3c95448b803b42d6c9723
Author: Anders Damsgaard Christensen <adc@geo.au.dk>
Date: Sun, 1 Jan 2017 11:38:48 -0800
use lstinline, add note on HEAD^ and HEAD^^
Diffstat:
2 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/git-quick-start.pdf b/git-quick-start.pdf
Binary files differ.
diff --git a/git-quick-start.tex b/git-quick-start.tex
@@ -78,18 +78,18 @@ On Debian-based systems, Git can be installed through the advanced package tool:
$ apt-get install git
\end{lstlisting}
-Git has excellent built-in documentation through its man page (i.e. \texttt{man
- git}). For documentation on a sub-command such as \texttt{git add}, see its
-documentation with \texttt{man git-add}. For more complex tasks, I recommend
-referring to a Git handbook or searching the web (in that order).
+Git has excellent built-in documentation through its man page (i.e.
+\lstinline{man git}). For documentation on a sub-command such as
+\lstinline{git add}, see its documentation with \lstinline{man git-add}. For
+more complex tasks, I recommend referring to a Git handbook or searching the web
+(in that order).
\section{Getting started}
Before using Git for version control, it is a good idea to record some
information about yourself. This makes it is easy to see who specific commits
can be attributed to when working on projects with multiple contributors. The
user information is stored in a plain-text file in the home directory
-(\texttt{\textasciitilde/.gitconfig}), and can be created with the following
-commands:
+(\lstinline{~/.gitconfig}), and can be created with the following commands:
\begin{lstlisting}
$ git config --global user.name "John Doe"
$ git config --global user.email "john-doe-farms@aol.com"
@@ -98,16 +98,16 @@ commands:
\section{Initializing a repository}
In order to track changes to files in a directory, the directory needs to be
initialized as a repository. Let's say that we want to track the changes to a
-file \texttt{arithmetic.c} which located in the directory
-\texttt{\textasciitilde/src/calculator}. We start off by initializing the
-directory as a repository:
+file \lstinline{arithmetic.c} which located in the directory
+\lstinline{~/src/calculator}. We start off by initializing the directory as a
+repository:
\begin{lstlisting}
$ cd ~/src/calculator
$ git init
Initialized empty Git repository in ~/src/calculator/.git/
\end{lstlisting}
Git lets us know that the directory is initialized as a new repository, and that
-the hidden sub-directory \texttt{.git} is used for the files related to the
+the hidden sub-directory \lstinline{.git} is used for the files related to the
version control\footnote{This directory contains many interesting files, and I
encourage you to explore it when you are more familiar with Git.}.
@@ -135,7 +135,7 @@ protocols such as SSH or HTTPS if you prefer.
The local repository will remember where it was cloned from. If you have write
permissions to the online repository, you can upload your local commits using
-\texttt{git push}.
+\lstinline{git push}.
\section{Adding files and commiting changes}
To add a file to the version-control system inside a repository, use the
@@ -165,8 +165,8 @@ following command:
\begin{lstlisting}
$ git commit -m "First commit of arithmetic.c"
\end{lstlisting}
-If you ommit the \texttt{-m} flag and message string (i.e. simply type
-\texttt{git commit}), Git will open your favorite command-line
+If you ommit the \lstinline{-m} flag and message string (i.e. simply type
+\lstinline{git commit}), Git will open your favorite command-line
editor\footnote{You can set which editor you want to use using the
\texttt{EDITOR} environment variable in e.g.
\texttt{\textasciitilde/.bashrc}.}. You then write the commit message in
@@ -178,7 +178,7 @@ once again. We can either once again add the file and commit the changes:
$ git add arithmetic.c
$ git commit -m "Implemented multiplication"
\end{lstlisting}
-Alternatively, since the file \texttt{arithmetic.c} is already added to the
+Alternatively, since the file \lstinline{arithmetic.c} is already added to the
repository, you can commit \emph{all} changes to \emph{all} tracked files in the
repository with a single command:
\begin{lstlisting}
@@ -233,7 +233,11 @@ change your mind and want to go back to the most recent commit, use:
\begin{lstlisting}
$ git revert HEAD
\end{lstlisting}
-The special string \texttt{HEAD} refers to the most recent commit.
+The special string \lstinline{HEAD} refers to the most recent commit, and the
+commit before that is referred to by \lstinline{HEAD^}, while the third-most
+recent commit is \lstinline{HEAD^^}. These special strings are convenient, for
+example when you want to see what changed during the most recent commit, which
+can be done with the command \lstinline{git diff HEAD^ HEAD filename}.
\section{Branching and merging}
Git allows you to have multiple versions (branches) of the same repository. The
@@ -241,20 +245,20 @@ first step is to create a new branch and give it a suitable name:
\begin{lstlisting}
$ git checkout -b new_interface
\end{lstlisting}
-Subsequent commits are staged to the new branch \texttt{new\_interface}. You
-can see which branches are present in the repository with \texttt{git branch}:
+Subsequent commits are staged to the new branch \lstinline{new\_interface}. You
+can see which branches are present in the repository with \lstinline{git branch}:
\begin{lstlisting}
$ git branch
master
* new_interface
\end{lstlisting}
-where \texttt{master} is the original branch. The asterisk denotes what current
+where \lstinline{master} is the original branch. The asterisk denotes what current
branch is active. You can switch between branches, which will automatically
apply all relevant patches to the affected files:
\begin{lstlisting}
$ git checkout master
\end{lstlisting}
-To delete a branch, use \texttt{git branch -d new\_interface}. To merge another
+To delete a branch, use \lstinline{git branch -d new\_interface}. To merge another
branch into your current active branch, use:
\begin{lstlisting}
$ git merge new_interface
@@ -265,10 +269,10 @@ the currently active branch.
\section{Ignoring files}
Many compilers create auxillary files which are never relevant to track in a
version-control system, but clutter your repository overview when using commands
-such as \texttt{git status} or \texttt{git commit -a}. You can specify which
+such as \lstinline{git status} or \lstinline{git commit -a}. You can specify which
files Git should ignore by their filename in a file at the root of the
-repository in a file named \texttt{.gitignore}.
-For a repository containing C code, an example \texttt{.gitignore} file could
+repository in a file named \lstinline{.gitignore}.
+For a repository containing C code, an example \lstinline{.gitignore} file could
contain:
\begin{lstlisting}
*.o
@@ -301,15 +305,15 @@ contain:
*.xdy
*.synctex.gz
\end{lstlisting}
-It is up to you to specify the contents of the \texttt{.gitignore} file. Maybe
+It is up to you to specify the contents of the \lstinline{.gitignore} file. Maybe
your program generates output files, which should not be tracked. Simply add
-their names or file type to the \texttt{.gitignore} file and never encounter
+their names or file type to the \lstinline{.gitignore} file and never encounter
them in your Git workflow again.
\section{Extra: Useful shell aliases}
I like to bind short aliases to the most commonly Git commands. I do this by
-appending the following to the \texttt{rc} file of my shell
-(\texttt{\textasciitilde/.zshrc} or \texttt{\textasciitilde/.bashrc}):
+appending the following to the \lstinline{rc} file of my shell
+(\lstinline{~/.zshrc} or \lstinline{~/.bashrc}):
\begin{lstlisting}
alias gs='git status | less'
alias gl='git log --graph --oneline --decorate --all'
@@ -322,13 +326,13 @@ appending the following to the \texttt{rc} file of my shell
alias gcgp='git commit --verbose && git push'
alias gcagp='git commit --all --verbose && git push'
\end{lstlisting}
-Using these aliases I can quickly add a file (\texttt{ga file.c}).
+Using these aliases I can quickly add a file (\lstinline{ga file.c}).
Alternatively, I can quickly commit all changes to all files that are already
-tracked in the repository (\texttt{gca}).
-With \texttt{gl} I can quickly see the commit tags and commit messages in short
-form, and scroll up and down with \texttt{j} and \texttt{k} or the arrow keys.
-\texttt{gs} gives me a quick overview of the changes in the current repository,
-and uses the same keys as \texttt{gl} for scrolling.
+tracked in the repository (\lstinline{gca}).
+With \lstinline{gl} I can quickly see the commit tags and commit messages in short
+form, and scroll up and down with \lstinline{j} and \lstinline{k} or the arrow keys.
+\lstinline{gs} gives me a quick overview of the changes in the current repository,
+and uses the same keys as \lstinline{gl} for scrolling.
\end{document}