(N) Creating .gitignore file¶
Goal:
I will learn how to put .gitignore file in my repository.
Instructions:
In your personal Git central repository, create/complete a
.gitignore file to eliminate build directories generated by
Qt Creator and files with .pro.user suffix from version control.
Important
This exercise is highly recommended, since it makes working on this course easier.
It is a good idea to do the exercise, even if its deadline has expired.
Note about the location and name of the file
You should find the aforementioned file in your home directory
from the same level as
the subdirectories examples, student, and templates.
Note that the name of the file begins with a dot.
Therefore, it will not be listed with the command line command
ls, but it will be listed with the command:
ls -a
Or if you try to find the files from the Files view, remember to
check the point Show Hidden Files.
Backgrounds¶
There exist files that are not wanted to be stored in version control.
For example, all the files in the build folder of Qt Creator can be
regenerated by performing build in Qt Creator, if the source code files
and project file exist.
Therefore it is not reasonable to store the content of the build folder
in Git.
We do not want to add the above kind of files by accident, for example,
with the command git add --all, or see the files with the command
git status.
The situation can be solved with the file called .gitignore.
This file is a normal text file, containing a list of all paths and files
that are meant to be left outside version control.
This file already exists in your repository, but you need to complete it.
The name of the .gitignore file begins with a dot.
Therefore you cannot see it in the list produced by the command line
command ls, but you can see it with the command ls -a.
Similarly, the file cannot be seen in Files view in the remote desktop,
unless you have checked Show Hidden Files.
At this point, recall using wild cards and what is meant, for example,
with *.txt or *~.
(If you do not remember these things, you can check them from
the second-last chapter Self study: Using Git in command line, section
Command line operations, at
Special characters in paths.)
Especially, note that in the place of the the character *, any number
(including zero) of any characters are allowed.
Initial actions¶
In your .gitignore file, there are already some lines that e.g. prevent
build directories to be tracked in the version control.
Do not remove nor modify these lines.
Here we mean all the subdirectories in your home directory that begin
with the text build, and after
this text any number of any characters are allowed.
Your task is to add in this file a line ignoring files ending with
.pro.user.
To see the effect of the line to be added, act first as follows:
In the root of your repository, create a new text file,
test.pro.user, in a way you have used to.
In the command line (Terminal), this can be done with the command:
touch test.pro.user
What says the command git status?
Completing the assignment¶
Open the file .gitignore with a text editor and add there a line
that recognizes all file names ending with *.pro.user.
How could you use the character * now?
See again how the status looks like.
You can test the behavior of your gitignore by using command the
git status.
If you add new files and git status does not show them as
“Untracked files:”, it means that your gitignore works at least in the
case of that file.
Tips for completing the assignment:
Make first sure that your repository has no unsaved modifications.
During the assignment, use the command
git statusto check the status, as guided previously.If desired, you can write also other lines in your
.gitignorefile to eliminate files with certain type from version control.Never ever add such files in your
.gitignorefile that you should submit, e.g. files with suffixes.cpp,.hh, or.pro.If you have earlier stored files ending with
.pro.userin your central repository, you can remove them with the commandgit rm.
A+ presents the exercise submission form here.