Skip to main content
Contents
Dark Mode Prev Up Next Profile
\(\newcommand{\N}{\mathbb N} \newcommand{\Z}{\mathbb Z} \newcommand{\Q}{\mathbb Q} \newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 3.6 Committing to Your Local Repository
In this section you will do the work necessary to commit the changes made to your
Local Files to your local repository. The process of committing changes is illustrated in
FigureΒ 3.6.1 .
Local file changes that have been staged are committed to the active branch.
Figure 3.6.1. Committing changes.
Exercises
1.
As you saw earlier when looking at the output of
git log
, each commit has a commit message that briefly describes the changes that are contained in the commit. These messages should be concise but meaningful without requiring the reader to refer to the ticket in the issue tracker. A future reader of the
git log
output should be able to obtain an idea of the changes you have made and why you made them by reading your commit messages.
For each of the following issues, order the given commit messages from best (listed first) to worst (listed last).
(a)
Issue: The documentation says βbugβ instead of βbugsβ where plural is needed.
Pluralize bug (i.e. bugs) for clarity
---
---
Hint .
Commit messages should be as specific as possible regarding the changes made. Something like "fix typo" is too generic as it can apply to lots of different changes.
(b)
Issue: The harvesting log should be able to track insect presence.
Add tracking for insects in harvesting logs
---
---
Hint .
Commit messages should be as specific as possible regarding the changes made. Which of the messages provides information about what is added and where?
2.
The
git commit -m "<message>"
command commits all of the staged files to the currently active branch with the specified commit message.
Write a
git commit
command for the change you made in the space below. Be sure to include a meaningful message.
3.
Use the
git commit
command you wrote in
ExerciseΒ 3.6.2 to commit your staged changes to your local repository with a meaningful commit message.
Look at the output produced.
It shows the name of the file changed in the square brackets [ ].
It shows the name of the feature branch that contains the change in the square brackets [ ].
It shows the SHA code of the commit in the square brackets [ ].
It shows the commit message.
It shows the number of files changed.
It shows the number of lines inserted.
It shows every line that was inserted and/or deleted.
Hint .
There should be two lines of output. The first will provide 3 different pieces of information. The second provides what additional information?
4.
(a)
Now use the
git status
command again. Compare your output to the output in
ExerciseΒ 3.5.2 . How does the output reflect that your changes have been staged?
No files appear listed as modified in red (meaning they are unstaged).
At this point, all files are staged.
No files appear listed as modified in green (meaning they are staged).
At this point, all files are staged and committed.
The output states "nothing to commit".
It is true that there is nothing to commit, but you need to look again at the other options.
Correct!
Hint .
You have staged and committed all modified files.
(b)
How do you know your changes have been committed?
The
git commit
message showed a new SHA.
The
git status
command does not show the files you modified for your change.
The
git status
command shows your modified files in green.
The
git commit
message says "no changes added to commit".
Hint .
There should be no modified files that are still staged and the
git commit
should have showed you the number of lines changed.
(c)
Use the
git log
command to show the 3 most recent commits to your branch. Refer back to your output from
TaskΒ 3.1.2.1.b .
Hint .
Look carefully at the dates of the commits shown in the log.
(d)
Make
main
your active branch. What command did you use?
git status
shows what files have been changed and staged.
git stage main
is not a proper command.
git branch main
would try to create a new branch named main
.
Correct!
Hint .
You want to change from the current branch back to the
main
branch.
(e)
Hint .
What branch are you on, the
main
branch or your feature branch? In which branch did you make your changes?
(f)
The commit is not shown in the
git log
output because:
You are on the
main
branch and the commit is on the feature branch.
Correct!
You are on the feature branch and the commit is on the
main
branch.
You should be on the main
branch.
The
git status
command should be used to show the commits.
The git status
command is used to see what files have been changed and staged.
It only shows the first commit made, not every commit.
The git log
command will show multiple commits with the most recent appearing first.
Hint .
Commits are specific to branches. You must be on the proper branch to see a commit.
You have attempted
of
activities on this page.