Updates to chapter 3
This commit is contained in:
parent
ae20025538
commit
fb947caf90
@ -31,7 +31,9 @@
|
||||
\usepackage[]{footmisc}
|
||||
\usepackage{ninecolors}
|
||||
\usepackage{setspace}
|
||||
\usepackage{tikz}
|
||||
\usepackage[obeyDraft, textcolor=red2, bordercolor=red, backgroundcolor=white, textsize=small]{todonotes}
|
||||
\usepackage{varwidth}
|
||||
|
||||
|
||||
%\usepackage{showframe}
|
||||
@ -311,7 +313,7 @@ Finally, it shows you \textit{untracked} files. In other words, these are files
|
||||
|
||||
Do you \textit{want} to track those untracked files? If you do, go ahead and add them using the \texttt{git add} command. If not, add them to the \texttt{.gitignore} file.
|
||||
|
||||
\section{Ignoring Certain Files}
|
||||
\section{Ignoring Files}
|
||||
|
||||
Suppose that you have files in your repository that you \textit{don't} want Git to keep track of. Perhaps they are just notes to yourself that you will later delete, or some test files will not be a permanent part of this project. In such a case, you can use an ignore file to tell Git to not worry about those files.
|
||||
|
||||
@ -369,7 +371,7 @@ If you want to see how many commits you have, you can use the \texttt{rev-list}
|
||||
|
||||
\input{include/revlist}
|
||||
|
||||
which will simply return a number indicating the number of commits, and thus how many screenfuls of information you may need to scroll through to find data from an early commit.
|
||||
This will simply return a number indicating the number of commits, and thus how many screenfuls of information you may need to scroll through to find data from an early commit.
|
||||
|
||||
However, you can use some options with \texttt{git log} to get just the information you need. For example, you the \texttt{--pretty=oneline} option to show only the SHA hash and the description for each commit on a single line.
|
||||
|
||||
@ -401,7 +403,7 @@ sends the output of that command to a file (\texttt{log.txt}), the first few lin
|
||||
|
||||
Here we get the date of the commit (in YYYY-MM-DD format), followed by an abbreviated commit hash, the name of the comitter (important if you have more than one person working on this project), and finally the commit description.
|
||||
|
||||
\section{Examinging Earlier Commits}
|
||||
\section{Examining Earlier Commits}
|
||||
|
||||
Now that you know how to find earlier commits, you need to know how to revert to one. To do that, you simply \texttt{checkout} the earlier commit, using just enough of the SHA-1 hash to be identifiable:
|
||||
|
||||
@ -413,14 +415,14 @@ To get back to the latest commit, we simply checkout our current branch, which i
|
||||
|
||||
\input{include/gitcheckoutmain}
|
||||
|
||||
Before checking out an earlier commit, you should make sure to add and commit any changes you have made since your last commit, to avoid losing any changes. (You can also use \texttt{git stash save} command to save your current work as a patch, then use \texttt{git stash apply} to re-apply your local changes. The exact details on this are beyond the scope of this document, however.)
|
||||
Before checking out an earlier commit, you should make sure to add and commit any changes you have made since your last commit, to avoid losing any recent changes. (You can also use \texttt{git stash save} command to save your current work as a patch, then use \texttt{git stash apply} to re-apply your local changes. The exact details on this are beyond the scope of this document, however.)
|
||||
|
||||
Of course, the easiest way to view older commits and examine them is by using a \textit{remote} repository, because their graphical interface is far easier to navigate.
|
||||
|
||||
|
||||
\chapter{Remote Repositories}
|
||||
|
||||
Remote repositories make it possible to share your work and to collaborate with others. You can do all sorts of things locally, but at some point, you're probably going to want to put your work out there, or to just show off.
|
||||
Remote repositories make it possible to share your work and to collaborate with others. You can do all sorts of things locally, but at some point, you're probably going to want to put your work out there either to share or collaborate, or to just show off.
|
||||
|
||||
\section{Getting a Remote Repository}
|
||||
|
||||
@ -432,18 +434,18 @@ For example, if you wanted to get a copy of the Apollo 11 Guidance Computer sour
|
||||
|
||||
If you want to see the remotes attached to this repo, you can just type \texttt{git remote -v}. In this case, it would show you something like this:
|
||||
|
||||
\begin{Verbatim}[]
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Output of git remote -v with one remote repository}]
|
||||
origin https://github.com/chrislgarry/Apollo-11 (fetch)
|
||||
origin https://github.com/chrislgarry/Apollo-11 (push)
|
||||
\end{Verbatim}
|
||||
|
||||
Of course, those remote repositories don't belong to you, so you can't push any changes you make to them. What you can do is create your own remote repo on a Git-hosting system. I've created one on Codeberg at \kref{https://codeberg.org/kjodle/Apollo-11}{https://codeberg.org/kjodle/Apol\\lo-11}. To add that remote to my local repo, I will use this:
|
||||
Of course, those remote repositories don't belong to you, so you can't push any changes you make to them. What you can do is create your own remote repo on a Git-hosting system. I've created one on Codeberg at \kref{https://codeberg.org/kjodle/Apollo-11}{https://codeberg.org/kjodle/Apol\\lo-11}. To add that remote to my local repo, I will use this command:
|
||||
|
||||
\input{include/remoteadd}
|
||||
|
||||
And running the \texttt{git remote -v} command again shows that I have two different remotes:
|
||||
|
||||
\begin{Verbatim}[]
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Output of git remote -v with two remote repositories}]
|
||||
berg https://codeberg.org/kjodle/Apollo-11 (fetch)
|
||||
berg https://codeberg.org/kjodle/Apollo-11 (push)
|
||||
origin https://github.com/chrislgarry/Apollo-11 (fetch)
|
||||
@ -456,22 +458,22 @@ I named my remote ``berg'', to distinguish it from the ``origin''. I need to get
|
||||
|
||||
Running \texttt{git remote -v} again shows that I now just have the remote on my own website:
|
||||
|
||||
\begin{Verbatim}[]
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Output of git remote -v after removing a remote repository}]
|
||||
berg https://codeberg.org/kjodle/Apollo-11 (fetch)
|
||||
berg https://codeberg.org/kjodle/Apollo-11 (push)
|
||||
\end{Verbatim}
|
||||
|
||||
Are we ready to upload this code from my local repository to my remote repo? Not yet. Let's see what our local branches are named by running \texttt{git branch}, which gives us this:
|
||||
Are we ready to upload this code from my local repository to my remote repo? Not yet. Let's see what our local branches are named by running \texttt{ git branch}, which gives us this:
|
||||
|
||||
\begin{Verbatim}[]
|
||||
* master
|
||||
\end{Verbatim}
|
||||
|
||||
In this case, I only have a single branch, which is named ``master''. It also has an asterisk because it's the current branch. The problem here is that Codeber always names branches ``main''. So I need to change that branch name by running
|
||||
In this case, I only have a single branch, which is named ``master''. It also has an asterisk because it's the current branch. The problem here is that Codeberg always names branches ``main''. So I need to change that branch name by running
|
||||
|
||||
\input{include/branchrename}
|
||||
|
||||
Running \texttt{git branch} again confirms that our branch has been renamed:
|
||||
Running \texttt{ git branch} again confirms that our branch has been renamed:
|
||||
|
||||
\begin{Verbatim}[]
|
||||
* main
|
||||
@ -485,7 +487,7 @@ Okay, I have a local repository, I have a remote repository attached to that loc
|
||||
|
||||
Git thought for a moment, and produced this output:
|
||||
|
||||
\begin{Verbatim}[breaklines=true]
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Output of git push command}]
|
||||
Enumerating objects: 3414, done.
|
||||
Counting objects: 100% (3414/3414), done.
|
||||
Delta compression using up to 4 threads
|
||||
@ -514,6 +516,33 @@ Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded.
|
||||
|
||||
If you are collaborating with other people on a project, you may see different messages here. Others working on the project may have made changes that will conflict with your changes and could be difficult or impossible to reconcile. Always communicate with other project owners and use branching to prevent this.
|
||||
|
||||
\subsection{A Note About \texttt{git push} Syntax}
|
||||
|
||||
This command sometimes confuses new users. To help you understand what is happening here, this is the basic structure of this command:
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\begin{tikzpicture}
|
||||
\draw (0,0) rectangle (.8,1.4);
|
||||
\node at (0.4,.7) {git};
|
||||
\end{tikzpicture}
|
||||
\raisebox{5mm}{\begin{Huge}$ \Rightarrow $\end{Huge}}
|
||||
\begin{tikzpicture}
|
||||
\draw (0,0) rectangle (1.2,1.4);
|
||||
\node at (0.6,.7) {push};
|
||||
\end{tikzpicture}
|
||||
\raisebox{5mm}{\begin{Huge}$ \Rightarrow $\end{Huge}}
|
||||
\begin{tikzpicture}
|
||||
\draw (0,0) rectangle (3.4,1.4);
|
||||
\node at (1.7,.7) [align=center] {\begin{varwidth}{3cm}\begin{center}where I'm pushing (i.e., the name of the remote repository)\end{center}\end{varwidth}};
|
||||
\end{tikzpicture}
|
||||
\raisebox{5mm}{\begin{Huge}$ \Rightarrow $\end{Huge}}
|
||||
\begin{tikzpicture}
|
||||
\draw (0,0) rectangle (3.4,1.4);
|
||||
\node at (1.7,.7) [align=center] {\begin{varwidth}{3cm}\begin{center}what I'm pushing (i.e., the name of the current branch)\end{center}\end{varwidth}};
|
||||
\end{tikzpicture}
|
||||
\end{figure}
|
||||
|
||||
|
||||
|
||||
\chapter{Branches}
|
||||
|
Loading…
Reference in New Issue
Block a user