Jose Robledo
04 March 2025
create a file called guacamole.md
that contains the
basic structure of our first recipe.
Include content
# Guacamole
## Ingredients
## Instructions
View content of file with cat
check status of our repository
We can tell Git to track a file using git add
check the status again. What changed?
Git now knows that it’s supposed to keep track of
guacamole.md
, but it hasn’t recorded these changes as a
commit yet. To get it to do that, we need to run one more command:
git commit
, Git takes everything we have told it to save
by using git add
and stores a copy permanently inside the
special .git
directory. This permanent copy is called a commit
(or revision)
and has an identifier and a short identifier.
We use the -m
flag (for “message”) to record a short,
descriptive, and specific comment that will help us remember later on
what we did and why.
Good commit messages start with a brief (<50
characters) statement about the changes made in the commit. Generally,
the message should complete the sentence “If applied, this commit will”
If we want to know what we’ve done recently, we can ask Git to show
us the project’s history using git log
:
Alfredo now wants to add more information to the Guacamole recipe, let’s say he wants it to look like:
# Guacamole
## Ingredients
* avocado
* lemon
* salt
## Instructions
git status
and observe the
outputWe have changed this file, but we haven’t told Git we will want to
save those changes (which we do with git add
) nor have we
saved them (which we do with git commit
).
comment: you might need to press q
to
exit the git diff
commmand. If you have colors on your
terminal, green (and +
symbols) are addition and red (and
-
symbols) are deletions.
Git has a special staging area where it keeps track of things that have been added to the current changeset but not yet committed.
git add
specifies what will
go in the staging area,git commit
then actually saves the
current snapshot of the repository, by making a permanent record of
the changes (as a commit).Improve our recipe by changing ‘lemon’ to ‘lime’
in guacamole.md
check the difference with
git diff
.
Since we agree with the changes, let’s add them
to the staging area, and now see which are the differences again with
git diff
. Anything different?
If you’re satisfied, save your changes (commit)!
comment: Sometimes, e.g. in the
case of the text documents a line-wise diff is too coarse. That is where
the --color-words
option of git diff
comes in
very useful as it highlights the changed words using colors.
When the output of git log
is too
long to fit in your screen, git
uses a program to split it
into pages of the size of your screen. When this “pager” is called, you
will notice that the last line in your screen is a :
,
instead of your usual prompt.
some_word
in all pages,
press / and type some_word
. Navigate through
matches pressing N. To navigate back matches press
Shift+N.git log -N
: Last N commits. For example--online
: reduce quantity of
information--graph
: display commit history as
text-based graph.gitkeep
inside the
directory.git add
command.Which of the following commit messages would be most appropriate for
the last commit made to guacamole.md
?
The staging area can hold changes from any number of files that you want to commit as a single snapshot.
guacamole.md
noting
the rough price of the ingredients.groceries.md
with a
list of products and their prices for different markets.bio
Repositorybio
.me.txt
, commit your changesContent